aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/daemon.c5
-rw-r--r--src/daemon.h4
-rw-r--r--src/parse_time.c2
-rw-r--r--src/satd-add.c14
-rw-r--r--src/satd-diminished.c2
-rw-r--r--src/satd-list.c49
-rw-r--r--src/satd-rm.c5
-rw-r--r--src/satd-run.c5
-rw-r--r--src/satd.c1
-rw-r--r--src/satq.c2
-rw-r--r--src/satrm.c2
11 files changed, 51 insertions, 40 deletions
diff --git a/src/daemon.c b/src/daemon.c
index 75e0f36..8221d6a 100644
--- a/src/daemon.c
+++ b/src/daemon.c
@@ -20,9 +20,6 @@
* DEALINGS IN THE SOFTWARE.
*/
#include "daemon.h"
-#include <unistd.h>
-#include <stdio.h>
-#include <fcntl.h>
@@ -148,7 +145,7 @@ reopen(int fd, int oflag)
int r, saved_errno;
sprintf(path, "/dev/fd/%i", fd);
- r = open(fd, oflag);
+ r = open(path, oflag);
if (r < 0)
return -1;
if (dup2(r, fd) == -1)
diff --git a/src/daemon.h b/src/daemon.h
index c642f66..bd4a7af 100644
--- a/src/daemon.h
+++ b/src/daemon.h
@@ -24,6 +24,10 @@
#include <string.h>
#include <time.h>
#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <assert.h>
#include <sys/socket.h>
diff --git a/src/parse_time.c b/src/parse_time.c
index bb1b59e..d461efd 100644
--- a/src/parse_time.c
+++ b/src/parse_time.c
@@ -174,8 +174,6 @@ parse_time_time(const char *str, struct timespec *ts, const char **end)
static int
parse_time_seconds(const char *str, struct timespec *ts, const char **end)
{
- size_t points = 0;
-
memset(ts, 0, sizeof(*ts));
ts->tv_sec = strtotime(str, end);
diff --git a/src/satd-add.c b/src/satd-add.c
index 497e32d..0d7d777 100644
--- a/src/satd-add.c
+++ b/src/satd-add.c
@@ -39,22 +39,26 @@ main(int argc, char *argv[])
size_t n = 0, elements = 0, i;
char *message = NULL;
int msg_argc;
- char **msg = NULL;
- t (reopen(STATE_FILENO, O_RDRW));
+ assert(argc == 4);
+ t (reopen(STATE_FILENO, O_RDWR));
/* Receive and validate message. */
t (readall(SOCK_FILENO, &message, &n));
shutdown(SOCK_FILENO, SHUT_RD);
- t (n < sizeof(int) + sizeof(clk) + sizeof(ts));
- n -= sizeof(int) + sizeof(clk) + sizeof(ts);
+ t (n < sizeof(int) + sizeof(clockid_t) + sizeof(struct timespec));
+ n -= sizeof(int) + sizeof(clockid_t) + sizeof(struct timespec);
msg_argc = *(int *)(message + n);
t ((msg_argc < 1) || !n || message[n - 1]);
for (i = n; i--; elements += !message[i]);
t (elements < (size_t)msg_argc);
- n += sizeof(int) + sizeof(clk) + sizeof(ts);
+ n += sizeof(int) + sizeof(clockid_t) + sizeof(struct timespec);
+
+ (void) argv;
return 0;
fail:
+
+ (void) argc;
}
diff --git a/src/satd-diminished.c b/src/satd-diminished.c
index a3a2807..606d8ec 100644
--- a/src/satd-diminished.c
+++ b/src/satd-diminished.c
@@ -84,7 +84,6 @@ main(int argc, char *argv[], char *envp[])
pid_t pid;
char type;
const char *image;
- struct stat _attr;
/* Set up signal handlers. */
if (signal(SIGHUP, sighandler) == SIG_ERR) goto fail;
@@ -109,7 +108,6 @@ accept_again:
goto fail;
}
}
-peek_again:
if (read(fd, &type, sizeof(char)) <= 0) {
perror(argv[0]);
goto connection_done;
diff --git a/src/satd-list.c b/src/satd-list.c
index 898c236..e6bcfd7 100644
--- a/src/satd-list.c
+++ b/src/satd-list.c
@@ -37,7 +37,7 @@
* `NULL` on error.
*/
static char *
-quote(const unsigned char *str)
+quote(const char *str)
{
size_t in = 0; /* < ' ' */
size_t sn = 0; /* = ' ', '"' or '$' */
@@ -45,10 +45,10 @@ quote(const unsigned char *str)
size_t qn = 0; /* = '\'' */
size_t rn = 0; /* other */
size_t n, i = 0;
- char *s;
+ const unsigned char *s;
char *rc;
- for (s = str; *s; s++) {
+ for (s = (const unsigned char *)str; *s; s++) {
if (*s < ' ') in++;
else if (*s == ' ') sn++;
else if (*s == '"') sn++;
@@ -65,7 +65,7 @@ quote(const unsigned char *str)
n = rn + sn + bn + 4 * qn + 4 * in + 2;
t (!(rc = malloc((n + 1) * sizeof(char))));
rc[i++] = '\'';
- for (s = str; *s; s++) {
+ for (s = (const unsigned char *)str; *s; s++) {
rc[i++] = (char)*s;
if (*s == '\'')
rc[i++] = '\\', rc[i++] = '\'', rc[i++] = '\'';
@@ -79,7 +79,7 @@ quote(const unsigned char *str)
t (!(rc = malloc((n + 1) * sizeof(char))));
rc[i++] = '$';
rc[i++] = '\'';
- for (s = str; *s; s++) {
+ for (s = (const unsigned char *)str; *s; s++) {
if (*s < ' ') {
rc[i++] = '\\';
rc[i++] = 'x';
@@ -113,12 +113,12 @@ static void
strduration(char *buffer, time_t s)
{
char *buf = buffer;
- int seconds, minutes, hours, days;
+ int seconds, minutes, hours;
seconds = s % 60, s /= 60;
minutes = s % 60, s /= 60;
hours = s % 24, s /= 24;
if (s) {
- buf += sprintf(buf, "%llid", (long long int)s));
+ buf += sprintf(buf, "%llid", (long long int)s);
buf += sprintf(buf, "%02i:", hours);
buf += sprintf(buf, "%02i", minutes);
} else if (hours) {
@@ -138,7 +138,7 @@ strduration(char *buffer, time_t s)
* @return 0 on success, -1 on error.
*/
static int
-send_job_str(struct job* job)
+send_job_human(struct job* job)
{
struct tm *tm;
struct timespec rem;
@@ -150,11 +150,12 @@ send_job_str(struct job* job)
char timestr_a[sizeof("0000-00-00 00:00:00") + 3 * sizeof(time_t)];
char timestr_b[10];
char **args = NULL;
- const char **arg;
- const char **argv = NULL;
- const char **envp = NULL;
+ char **arg;
+ char **argv = NULL;
+ char **envp = NULL;
size_t argsn;
int rc = 0;
+ int saved_errno;
/* Get remaining time. */
if (clock_gettime(job->clk, &rem))
@@ -182,8 +183,8 @@ send_job_str(struct job* job)
/* Get textual representation of the expiration time. */
switch (job->clk) {
case CLOCK_REALTIME:
- t (!(tm = localtime(job->ts.tv_sec)));
- strftime(timestr_a, sizeof(timestr), "%Y-%m-%d %H:%M:%S", tm);
+ t (!(tm = localtime(&(job->ts.tv_sec))));
+ strftime(timestr_a, sizeof(timestr_a), "%Y-%m-%d %H:%M:%S", tm);
break;
default:
strduration(timestr_a, job->ts.tv_sec);
@@ -193,8 +194,8 @@ send_job_str(struct job* job)
/* Get arguments. */
t (!(args = restore_array(job->payload, job->n, &argsn)));
- t (!(argv = sublist(args, (size_t)argc)));
- t (!(envp = sublist(args + argc, argsn - (size_t)argc)));
+ t (!(argv = sublist(args, (size_t)(job->argc))));
+ t (!(envp = sublist(args + job->argc, argsn - (size_t)(job->argc))));
/* Send message. */
t (!(qstr = quote(args[0])));
@@ -205,15 +206,15 @@ send_job_str(struct job* job)
" time: ", timestr_a, ".", timestr_b, "\n",
" argv:",
NULL));
- for (arg = argv, *arg, arg++) {
+ for (arg = argv; *arg; arg++) {
free(qstr);
- t (!(qstr = quote(arg)));
+ t (!(qstr = quote(*arg)));
t (send_string(SOCK_FILENO, STDOUT_FILENO, " ", qstr, NULL));
}
free(qstr), qstr = NULL;
t (send_string(SOCK_FILENO, STDOUT_FILENO, "\n envp:", NULL));
- for (arg = envp, *arg, arg++) {
- t (!(qstr = quote(arg)));
+ for (arg = envp; *arg; arg++) {
+ t (!(qstr = quote(*arg)));
t (send_string(SOCK_FILENO, STDOUT_FILENO, " ", qstr, NULL));
free(qstr);
}
@@ -253,8 +254,10 @@ main(int argc, char *argv[])
char *message = NULL;
struct job** jobs;
struct job** job;
+ int rc = 0;
- t (reopen(STATE_FILENO, O_RDRW));
+ assert(argc == 4);
+ t (reopen(STATE_FILENO, O_RDWR));
/* Receive and validate message. */
t (readall(SOCK_FILENO, &message, &n) || n);
@@ -263,7 +266,7 @@ main(int argc, char *argv[])
/* Perform action. */
t (!(jobs = get_jobs()));
for (job = jobs; *job; job++)
- t (send_job_str(*job));
+ t (send_job_human(*job));
done:
/* Cleanup. */
@@ -275,9 +278,11 @@ done:
free(message);
return rc;
fail:
- if (send_string(SOCK_FILENO, STDERR_FILENO, argv[0], ": ", strerror(errno) "\n", NULL))
+ if (send_string(SOCK_FILENO, STDERR_FILENO, argv[0], ": ", strerror(errno), "\n", NULL))
perror(argv[0]);
rc = 1;
goto done;
+
+ (void) argc;
}
diff --git a/src/satd-rm.c b/src/satd-rm.c
index 4feb93a..3229b68 100644
--- a/src/satd-rm.c
+++ b/src/satd-rm.c
@@ -42,7 +42,8 @@ main(int argc, char *argv[])
char **arg;
int rc = 0;
- t (reopen(STATE_FILENO, O_RDRW));
+ assert(argc == 4);
+ t (reopen(STATE_FILENO, O_RDWR));
/* Receive and validate message. */
t (readall(SOCK_FILENO, &message, &n) || !n || message[n - 1]);
@@ -66,5 +67,7 @@ fail:
perror(argv[0]);
rc = 1;
goto done;
+
+ (void) argc;
}
diff --git a/src/satd-run.c b/src/satd-run.c
index 0ade981..95551b0 100644
--- a/src/satd-run.c
+++ b/src/satd-run.c
@@ -42,7 +42,8 @@ main(int argc, char *argv[])
char **arg;
int rc = 0;
- t (reopen(STATE_FILENO, O_RDRW));
+ assert(argc == 4);
+ t (reopen(STATE_FILENO, O_RDWR));
/* Receive and validate message. */
t (readall(SOCK_FILENO, &message, &n) || (n && message[n - 1]));
@@ -74,5 +75,7 @@ fail:
perror(argv[0]);
rc = 1;
goto done;
+
+ (void) argc;
}
diff --git a/src/satd.c b/src/satd.c
index f7b6360..6daf7cf 100644
--- a/src/satd.c
+++ b/src/satd.c
@@ -204,7 +204,6 @@ main(int argc, char *argv[])
{
struct sockaddr_un address;
int sock = -1, state = -1, foreground = 0;
- struct stat attr;
char *path = NULL;
char *dir;
ssize_t len;
diff --git a/src/satq.c b/src/satq.c
index 0b110f5..ba04bf3 100644
--- a/src/satq.c
+++ b/src/satq.c
@@ -45,7 +45,7 @@ main(int argc, char *argv[])
if (argc > 0) argv0 = argv[0];
if (argc > 1) usage();
- SEND(SAT_PRINT, 0, NULL));
+ SEND(SAT_PRINT, 0, NULL);
END(NULL);
}
diff --git a/src/satrm.c b/src/satrm.c
index 0a9eccf..767782c 100644
--- a/src/satrm.c
+++ b/src/satrm.c
@@ -51,7 +51,7 @@ main(int argc, char *argv[])
NO_OPTIONS;
CONSTRUCT_MESSAGE;
- SEND(SAT_REMOVE, n, msg));
+ SEND(SAT_REMOVE, n, msg);
END(msg);
}