2 static unsigned short int client_id
= 0;
3 static const char *cmdpath
= NULL
;
5 /* glibc has a non-standard realpath(3) implementation which allocates
6 * the destination buffer, other C libraries may have a broken implementation
7 * which expect an already allocated destination buffer.
13 # define PATH_MAX 1024
17 static char *get_realpath(const char *path
) {
19 return realpath(path
, NULL
);
21 static char buf
[PATH_MAX
];
22 return realpath(path
, buf
);
27 get_cmd_by_name(const char *name
) {
28 for (int i
= 0; i
< countof(commands
); i
++) {
29 if (!strcmp(name
, commands
[i
].name
))
38 char *p
, *s
, cmdbuf
[512], c
;
40 switch (r
= read(cmdfd
, cmdbuf
, sizeof cmdbuf
- 1)) {
49 /* find the command name */
50 for (; *p
== ' ' || *p
== '\n'; p
++);
51 for (s
= p
; *p
&& *p
!= ' ' && *p
!= '\n'; p
++);
54 if (*s
&& (cmd
= get_cmd_by_name(s
)) != NULL
) {
57 /* XXX: initializer assumes MAX_ARGS == 2 use a initialization loop? */
58 const char *args
[MAX_ARGS
] = { NULL
, NULL
}, *arg
;
59 /* if arguments were specified in config.h ignore the one given via
60 * the named pipe and thus skip everything until we find a new line
62 if (cmd
->action
.args
[0] || c
== '\n') {
63 debug("execute %s", s
);
64 cmd
->action
.cmd(cmd
->action
.args
);
65 while (*p
&& *p
!= '\n')
69 /* no arguments were given in config.h so we parse the command line */
73 for (; (c
= *p
); p
++) {
76 /* remove the escape character '\\' move every
77 * following character to the left by one position
100 /* remove trailing quote if there is one */
101 if (*(p
- 1) == '\'' || *(p
- 1) == '\"')
104 /* remove leading quote if there is one */
105 if (*arg
== '\'' || *arg
== '\"')
117 if (c
== '\n' || *p
== '\n') {
118 debug("execute %s", s
);
119 for(int i
= 0; i
< argc
; i
++)
120 debug(" %s", args
[i
]);
122 cmd
->action
.cmd(args
);