Skip to content

Commit 98596b6

Browse files
committed
Refactor: Drop tk_test macro
I found it confusing, because it was unclear that it referred to a member of the object pointed to by tk. Signed-off-by: Reid Wahl <[email protected]>
1 parent 92eab33 commit 98596b6

File tree

4 files changed

+38
-39
lines changed

4 files changed

+38
-39
lines changed

src/config.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,8 @@ read_time(char *val)
398398
}
399399

400400
/* make arguments for execv(2)
401-
* tk_test.path points to the path
402-
* tk_test.argv is argument vector (starts with the prog)
401+
* tk->clu_test.path points to the path
402+
* tk->clu_test.argv is argument vector (starts with the prog)
403403
* (strtok pokes holes in the configuration parameter value, i.e.
404404
* we don't need to allocate memory for arguments)
405405
*/
@@ -409,24 +409,24 @@ parse_extprog(char *val, struct ticket_config *tk)
409409
char *p;
410410
int i = 0;
411411

412-
if (tk_test.path) {
413-
free(tk_test.path);
412+
if (tk->clu_test.path) {
413+
free(tk->clu_test.path);
414414
}
415-
if (!(tk_test.path = strdup(val))) {
415+
if (!(tk->clu_test.path = strdup(val))) {
416416
log_error("out of memory");
417417
return -1;
418418
}
419419

420-
p = strtok(tk_test.path, " \t");
421-
tk_test.argv[i++] = p;
420+
p = strtok(tk->clu_test.path, " \t");
421+
tk->clu_test.argv[i++] = p;
422422
do {
423423
p = strtok(NULL, " \t");
424424
if (i >= MAX_ARGS) {
425425
log_error("too many arguments for the acquire-handler");
426-
free(tk_test.path);
426+
free(tk->clu_test.path);
427427
return -1;
428428
}
429-
tk_test.argv[i++] = p;
429+
tk->clu_test.argv[i++] = p;
430430
} while (p);
431431

432432
return 0;

src/config.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ typedef enum {
5858
EXTPROG_IGNORE,
5959
} extprog_state_e;
6060

61-
#define tk_test tk->clu_test
62-
6361
typedef enum {
6462
ATTR_OP_EQ = 1,
6563
ATTR_OP_NE,

src/handler.c

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ run_ext_prog(const struct booth_config *conf, struct ticket_config *tk,
7777
}
7878
closefiles(); /* don't leak open files */
7979
tk_log_debug("running handler %s", prog);
80-
execv(prog, tk_test.argv);
80+
execv(prog, tk->clu_test.argv);
8181
tk_log_error("%s: execv failed (%s)", prog, strerror(errno));
8282
_exit(1);
8383
}
@@ -117,7 +117,7 @@ test_exit_status(struct ticket_config *tk, char *prog, int status, int log_msg)
117117
static void
118118
reset_test_state(struct ticket_config *tk)
119119
{
120-
tk_test.pid = 0;
120+
tk->clu_test.pid = 0;
121121
set_progstate(tk, EXTPROG_IDLE);
122122
}
123123

@@ -126,7 +126,8 @@ tk_test_exit_status(struct ticket_config *tk)
126126
{
127127
int rv;
128128

129-
rv = test_exit_status(tk, tk_test.path, tk_test.status, !tk_test.is_dir);
129+
rv = test_exit_status(tk, tk->clu_test.path, tk->clu_test.status,
130+
!tk->clu_test.is_dir);
130131
reset_test_state(tk);
131132
return rv;
132133
}
@@ -141,15 +142,15 @@ wait_child(struct booth_config *conf, int sig)
141142
struct ticket_config *tk = iter->data;
142143
int status = 0;
143144

144-
if (tk_test.path && tk_test.pid > 0 &&
145-
(tk_test.progstate == EXTPROG_RUNNING ||
146-
tk_test.progstate == EXTPROG_IGNORE) &&
147-
waitpid(tk_test.pid, &status, WNOHANG) == tk_test.pid) {
148-
if (tk_test.progstate == EXTPROG_IGNORE) {
145+
if (tk->clu_test.path && tk->clu_test.pid > 0 &&
146+
(tk->clu_test.progstate == EXTPROG_RUNNING ||
147+
tk->clu_test.progstate == EXTPROG_IGNORE) &&
148+
waitpid(tk->clu_test.pid, &status, WNOHANG) == tk->clu_test.pid) {
149+
if (tk->clu_test.progstate == EXTPROG_IGNORE) {
149150
/* not interested in the outcome */
150151
reset_test_state(tk);
151152
} else {
152-
tk_test.status = status;
153+
tk->clu_test.status = status;
153154
set_progstate(tk, EXTPROG_EXITED);
154155
}
155156
}
@@ -178,18 +179,18 @@ ext_prog_timeout(struct ticket_config *tk)
178179
int
179180
is_ext_prog_running(struct ticket_config *tk)
180181
{
181-
if (!tk_test.path)
182+
if (!tk->clu_test.path)
182183
return 0;
183-
return (tk_test.pid > 0 && tk_test.progstate == EXTPROG_RUNNING);
184+
return (tk->clu_test.pid > 0) && (tk->clu_test.progstate == EXTPROG_RUNNING);
184185
}
185186

186187
void
187188
ignore_ext_test(struct ticket_config *tk)
188189
{
189190
if (is_ext_prog_running(tk)) {
190-
(void)kill(tk_test.pid, SIGTERM);
191+
(void)kill(tk->clu_test.pid, SIGTERM);
191192
set_progstate(tk, EXTPROG_IGNORE);
192-
} else if (tk_test.progstate == EXTPROG_EXITED) {
193+
} else if (tk->clu_test.progstate == EXTPROG_EXITED) {
193194
/* external prog exited, but the status not yet examined;
194195
* we're not interested in checking the status anymore */
195196
reset_test_state(tk);
@@ -207,22 +208,22 @@ process_ext_dir(const struct booth_config *conf, struct ticket_config *tk)
207208
signal(SIGCHLD, SIG_DFL);
208209
signal(SIGUSR1, SIG_DFL);
209210
signal(SIGINT, SIG_DFL);
210-
tk_log_debug("running programs in directory %s", tk_test.path);
211-
n_progs = scandir(tk_test.path, &proglist, prog_filter, alphasort);
211+
tk_log_debug("running programs in directory %s", tk->clu_test.path);
212+
n_progs = scandir(tk->clu_test.path, &proglist, prog_filter, alphasort);
212213
if (n_progs == -1) {
213-
tk_log_error("%s: scandir failed (%s)", tk_test.path, strerror(errno));
214+
tk_log_error("%s: scandir failed (%s)", tk->clu_test.path, strerror(errno));
214215
_exit(1);
215216
}
216217
for (i = 0; i < n_progs; i++) {
217218
if (ignore_status)
218219
break;
219220
dp = proglist[i];
220-
if (strlen(dp->d_name) + strlen(tk_test.path) + 1 > FILENAME_MAX) {
221+
if (strlen(dp->d_name) + strlen(tk->clu_test.path) + 1 > FILENAME_MAX) {
221222
tk_log_error("%s: name exceeds max length (%s)",
222-
tk_test.path, dp->d_name);
223+
tk->clu_test.path, dp->d_name);
223224
_exit(1);
224225
}
225-
strcpy(prog, tk_test.path);
226+
strcpy(prog, tk->clu_test.path);
226227
strcat(prog, "/");
227228
strcat(prog, dp->d_name);
228229
switch(curr_pid=fork()) {
@@ -266,27 +267,27 @@ run_handler(const struct booth_config *conf, struct ticket_config *tk)
266267
pid_t pid;
267268
struct stat stbuf;
268269

269-
if (!tk_test.path)
270+
if (!tk->clu_test.path)
270271
return 0;
271272

272-
if (stat(tk_test.path, &stbuf)) {
273-
tk_log_error("%s: stat failed (%s)", tk_test.path, strerror(errno));
273+
if (stat(tk->clu_test.path, &stbuf)) {
274+
tk_log_error("%s: stat failed (%s)", tk->clu_test.path, strerror(errno));
274275
return RUNCMD_ERR;
275276
}
276-
tk_test.is_dir = (stbuf.st_mode & S_IFDIR);
277+
tk->clu_test.is_dir = (stbuf.st_mode & S_IFDIR);
277278

278279
switch(pid=fork()) {
279280
case -1:
280281
log_error("fork: %s", strerror(errno));
281282
return RUNCMD_ERR;
282283
case 0: /* child */
283-
if (tk_test.is_dir) {
284+
if (tk->clu_test.is_dir) {
284285
process_ext_dir(conf, tk);
285286
} else {
286-
run_ext_prog(conf, tk, tk_test.path);
287+
run_ext_prog(conf, tk, tk->clu_test.path);
287288
}
288289
default: /* parent */
289-
tk_test.pid = pid;
290+
tk->clu_test.pid = pid;
290291
set_progstate(tk, EXTPROG_RUNNING);
291292
rv = RUNCMD_MORE; /* program runs */
292293
}

src/ticket.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,11 @@ do_ext_prog(struct booth_config *conf, struct ticket_config *tk,
284284
{
285285
int rv = 0;
286286

287-
if (!tk_test.path) {
287+
if (!tk->clu_test.path) {
288288
return 0;
289289
}
290290

291-
switch(tk_test.progstate) {
291+
switch(tk->clu_test.progstate) {
292292
case EXTPROG_IDLE:
293293
rv = run_handler(conf, tk);
294294
if (rv == RUNCMD_ERR) {

0 commit comments

Comments
 (0)