X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=extras%2Fcollect%2Fcollect.c;h=7ebe865b62c7e5864c60cc4df5b2700e0a10d375;hp=feb0e7576871551e6e5984c32a0e43d51a79b9dc;hb=f183b6ed766a18835d53dc1e36a4e98756ebd0b7;hpb=b5254b42032b39e393f5c89102ca71c2b3fa0d11 diff --git a/extras/collect/collect.c b/extras/collect/collect.c index feb0e7576..7ebe865b6 100644 --- a/extras/collect/collect.c +++ b/extras/collect/collect.c @@ -31,9 +31,9 @@ #include #include -#include "../../list.h" +#include "../../udev/list.h" -#define TMPFILE "/dev/.udev/collect" +#define TMPFILE UDEV_PREFIX "/dev/.udev/collect" #define BUFSIZE 16 #define UDEV_ALARM_TIMEOUT 180 @@ -53,7 +53,7 @@ static LIST_HEAD(bunch); static int debug; /* This can increase dynamically */ -static int bufsize = BUFSIZE; +static size_t bufsize = BUFSIZE; static void sig_alrm(int signo) { @@ -147,7 +147,7 @@ static int checkout(int fd) if (!ptr && word < (buf + len)) { bufsize = bufsize << 1; if (debug) - fprintf(stderr, "ID overflow, restarting with size %d\n", bufsize); + fprintf(stderr, "ID overflow, restarting with size %zi\n", bufsize); free(buf); lseek(fd, 0, SEEK_SET); goto restart; @@ -272,8 +272,15 @@ static int missing(int fd) ret++; } else { while (strlen(him->name)+1 >= bufsize) { + char *tmpbuf; + bufsize = bufsize << 1; - buf = realloc(buf, bufsize); + tmpbuf = realloc(buf, bufsize); + if (!tmpbuf) { + free(buf); + return -1; + } + buf = tmpbuf; } snprintf(buf, strlen(him->name)+2, "%s ", him->name); write(fd, buf, strlen(buf)); @@ -314,10 +321,10 @@ static void everybody(void) int main(int argc, char **argv) { static const struct option options[] = { - { "add", 0, NULL, 'a' }, - { "remove", 0, NULL, 'r' }, - { "debug", 0, NULL, 'd' }, - { "help", 0, NULL, 'h' }, + { "add", no_argument, NULL, 'a' }, + { "remove", no_argument, NULL, 'r' }, + { "debug", no_argument, NULL, 'd' }, + { "help", no_argument, NULL, 'h' }, {} }; int argi;