Skip to content

Commit

Permalink
task: Simplify and remove some dead code
Browse files Browse the repository at this point in the history
Stop using w_obj_t as base struct for task_t and remove the unused
task_new() and _task_free() functions.
  • Loading branch information
aperezdc committed May 24, 2020
1 parent 1260f44 commit ad0b37b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 51 deletions.
45 changes: 1 addition & 44 deletions task.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* task.c
* Copyright (C) 2010 Adrian Perez <[email protected]>
* Copyright (C) 2010-2020 Adrian Perez <[email protected]>
*
* Distributed under terms of the MIT license.
*/
Expand All @@ -18,49 +18,6 @@
#include <grp.h> /* setgroups() */


static void
_task_free (void *taskptr)
{
task_t *task = taskptr;

if (task->argc) {
int i;
assert (task->argv);

for (i = 0; i < task->argc; i++)
free (task->argv[i]);

task->argv = 0;
task->argv = NULL;
}
}


task_t*
task_new (int argc, const char **argv)
{
task_t template = TASK;
task_t *task = w_obj_new (task_t);
memcpy (((w_obj_t*) task) + 1,
((w_obj_t*) &template) + 1,
sizeof (task_t) - sizeof (w_obj_t));

if (argc) {
int i;
assert (argv);

task->argv = w_alloc (char*, argc);
for (i = 0; i < argc; i++)
task->argv[i] = w_str_dup (argv[i]);
task->argc = argc;
}
else {
assert (argv == NULL);
}
return (task_t*) w_obj_dtor (task, _task_free);
}


void
task_start (task_t *task)
{
Expand Down
11 changes: 4 additions & 7 deletions task.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* task.h
* Copyright (C) 2010 Adrian Perez <[email protected]>
* Copyright (C) 2010-2020 Adrian Perez <[email protected]>
*
* Distributed under terms of the MIT license.
*/
Expand All @@ -19,9 +19,7 @@ typedef enum {
} action_t;


W_OBJ (task_t)
{
w_obj_t parent;
typedef struct {
pid_t pid;
action_t action;
int argc;
Expand All @@ -32,12 +30,11 @@ W_OBJ (task_t)
time_t started;
uidgid_t user;
unsigned redir_errfd;
};
} task_t;

#define NO_PID (-1)
#define NO_SIGNAL (-1)
#define TASK { W_OBJ_STATIC (NULL), \
NO_PID, \
#define TASK { NO_PID, \
A_START, \
0, \
NULL, \
Expand Down

0 comments on commit ad0b37b

Please sign in to comment.