This source file includes following definitions.
- job_add
- job_runqueue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 #include "config.h"
23
24 #include <stdlib.h>
25 #include <pwd.h>
26 #include <errno.h>
27 #include <sys/types.h>
28 #include <unistd.h>
29 #include <string.h>
30
31 #include "funcs.h"
32 #include "globals.h"
33
34 typedef struct _job {
35 struct _job *next;
36 entry *e;
37 user *u;
38 } job;
39
40 static job *jhead = NULL, *jtail = NULL;
41
42 void job_add(entry * e, user * u) {
43 job *j;
44 struct passwd *newpwd;
45 struct passwd *temppwd;
46 const char *uname;
47
48
49 for (j = jhead; j != NULL; j = j->next)
50 if (j->e == e && j->u == u)
51 return;
52
53 uname = e->pwd->pw_name;
54
55 if ((temppwd = getpwnam(uname)) != NULL) {
56 char **tenvp;
57
58 Debug(DSCH | DEXT, ("user [%s:%ld:%ld:...] cmd=\"%s\"\n",
59 e->pwd->pw_name, (long) temppwd->pw_uid,
60 (long) temppwd->pw_gid, e->cmd));
61 if ((newpwd = pw_dup(temppwd)) == NULL) {
62 log_it(uname, getpid(), "ERROR", "memory allocation failed", errno);
63 return;
64 }
65 free(e->pwd);
66 e->pwd = newpwd;
67
68 if ((tenvp = env_update_home(e->envp, e->pwd->pw_dir)) == NULL) {
69 log_it(uname, getpid(), "ERROR", "memory allocation failed", errno);
70 return;
71 }
72 e->envp = tenvp;
73 } else {
74 log_it(uname, getpid(), "ERROR", "getpwnam() failed - user unknown",errno);
75 Debug(DSCH | DEXT, ("%s:%d pid=%d time=%ld getpwnam(%s) failed errno=%d error=%s\n",
76 __FILE__,__LINE__,getpid(),time(NULL),uname,errno,strerror(errno)));
77 return;
78 }
79
80
81 if ((j = (job *) malloc(sizeof (job))) == NULL)
82 return;
83 j->next = NULL;
84 j->e = e;
85 j->u = u;
86
87
88 if (jhead == NULL)
89 jhead = j;
90 else
91 jtail->next = j;
92 jtail = j;
93 }
94
95 int job_runqueue(void) {
96 job *j, *jn;
97 int run = 0;
98
99 for (j = jhead; j; j = jn) {
100 do_command(j->e, j->u);
101 jn = j->next;
102 free(j);
103 run++;
104 }
105 jhead = jtail = NULL;
106 return (run);
107 }