job-args c-job-args
job-start-trigger c-job-start-trigger
job-end-trigger c-job-end-trigger
+ job-name c-job-name
c-check-job))
;;; records
(define-record-type <job>
- (make-job command-line args start-trigger end-trigger)
+ (make-job name command-line args start-trigger end-trigger)
job?
+ (name job-name)
(command-line job-command-line)
(args job-args)
(start-trigger job-start-trigger)
(define (c-job-end-trigger obj)
(job-end-trigger obj))
+(define (c-job-name obj)
+ (job-name obj))
+
;;; functions
(define (get-keyword-value args keyword default)
(let ((keyword-value (memq keyword args)))
(let ((command-line (get-keyword-value rest #:command-line #f))
(args (get-keyword-value rest #:args (list)))
(start-trigger (get-keyword-value rest #:start-trigger 'login))
- (end-trigger (get-keyword-value rest #:end-trigger #f)))
+ (end-trigger (get-keyword-value rest #:end-trigger #f))
+ (name (get-keyword-value rest #:name #f)))
;; do thing with keyword-ed variables
;; (display "settings:") (newline)
;; (format (current-output-port)
;; (newline)
;; create a new object that represents the args given.
- (make-job command-line
+ (make-job name
+ command-line
args
start-trigger
end-trigger)
/* along with tomd. If not, see <http://www.gnu.org/licenses/>. */
struct job{
+ char *name;
char *cmd;
char *args[10];
/* todo */
#include "macros.h"
WRAP_SCM_FUNCTION_1("tomd job", "c-check-job", job_predicate)
+WRAP_SCM_FUNCTION_1("tomd job", "c-job-name", get_name)
WRAP_SCM_FUNCTION_1("tomd job", "c-job-cmd", get_cmd)
WRAP_SCM_FUNCTION_1("tomd job", "c-job-args", get_args)
WRAP_SCM_FUNCTION_1("tomd job", "c-job-start-trigger", get_start_trigger)
#include <libguile.h>
#include <pwd.h>
+#include <fcntl.h>
+#include <string.h>
#include "../../include/job.h"
#include "../../include/macros.h"
return ret;
}
+ SCM scm_name = get_name(scm_cur_job);
SCM scm_cmd = get_cmd(scm_cur_job);
SCM scm_args = get_args(scm_cur_job);
SCM scm_start_trigger = get_start_trigger(scm_cur_job);
SCM scm_end_trigger = get_end_trigger(scm_cur_job);
+ char *job_name = scm_to_locale_string(scm_name);
char *job_cmd = scm_to_locale_string(scm_cmd);
-
char *real_args[10];
int jlen = scm_to_int(scm_length(scm_args));
for(int j = 0;
scm_to_locale_string(SCM_ARR(scm_args, j));
}
+ ret.name = job_name;
ret.cmd = job_cmd;
for(int j = 1;
}
}
+#define LOG_DIR "/var/log/tomd/"
+
void run_job(int index)
{
struct job *job = &jobs[index];
pid_t pid = fork();
if(pid == 0){ /* child */
- int i = 0;
- while(1){
- tomd_p("hallo");
- if(job->args[i] == NULL){
- tomd_p("arg [%d] is NULL", i);
- break;
- }else{
- tomd_p("arg [%d] is '%s'", i, job->args[i]);
- }
- i++;
+ /* int i = 0; */
+ /* while(1){ */
+ /* tomd_p("hallo"); */
+ /* if(job->args[i] == NULL){ */
+ /* tomd_p("arg [%d] is NULL", i); */
+ /* break; */
+ /* }else{ */
+ /* tomd_p("arg [%d] is '%s'", i, job->args[i]); */
+ /* } */
+ /* i++; */
+ /* } */
+
+ /* redirect to a file */
+ char buf[100];
+ strcpy(buf, LOG_DIR);
+ strcpy(buf + strlen(LOG_DIR), job->name);
+ tomd_p("redirecting stdout to %s.", buf);
+ if(unlink(buf) != 0){
+ perror("file couldn't be removed.");
}
+
+ int fd = open(buf, O_WRONLY | O_CREAT, 0644);
+ if(fd < 0){
+ perror("[tomd] couldn't open file.");
+ return;
+ }
+
+ dup2(fd, STDOUT_FILENO);
+ dup2(fd, STDERR_FILENO);
+ close(fd);
execvp(job->cmd, job->args);
tomd_p("execvp for '%s' failed", job->cmd);
perror("");
--- /dev/null
+/* Copyright (C) 2018 Thomas Balzer */
+
+/* This file is part of tomd. */
+
+/* tomd is free software: you can redistribute it and/or modify */
+/* it under the terms of the GNU General Public License as published by */
+/* the Free Software Foundation, either version 3 of the License, or */
+/* (at your option) any later version. */
+
+/* tomd is distributed in the hope that it will be useful, */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
+/* GNU General Public License for more details. */
+
+/* You should have received a copy of the GNU General Public License */
+/* along with tomd. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/un.h>
+#include <sys/socket.h>
+#include <unistd.h>
+
+static int sfd;
+
+static void init(void)
+{
+ /* init socket connection */
+ sfd =
+ socket(PF_LOCAL,
+ SOCK_STREAM,
+ 0);
+ if(sfd < 0){
+ perror("socket");
+ exit(EXIT_FAILURE);
+ }
+
+ struct sockaddr_un addr;
+ addr.sun_family = AF_LOCAL;
+ sprintf(addr.sun_path, "/run/user/1000/tomd/socket");
+
+ if(connect(sfd, (struct sockaddr *) &addr, SUN_LEN(&addr)) != 0){
+ perror("connect");
+ exit(EXIT_FAILURE);
+ }
+}
+
+#define HALLO "hallo there from dumb-client"
+
+void write_hallo(void)
+{
+ printf("writing hallo\n");
+ ssize_t wrote =
+ write(sfd, HALLO, sizeof HALLO);
+ printf("wrote %d bytes.\n", wrote);
+}
+
+static void header(void)
+{
+ tomd_p("Tom's Client, Copyright (C) 2018 Thomas Balzer");
+ tomd_p("GPL v3 or later license.");
+}
+
+int main(int argc, char **argv)
+{
+ header();
+ init();
+ write_hallo();
+
+ return EXIT_SUCCESS;
+}