X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=extras%2Fcollect%2Fcollect.c;h=14184a5e058977361d9927afce60005e8517d806;hp=0a852f2db239b2d4050a3ec3b90371c273ddf3ee;hb=a689165b5a140cd7d5fdd63cacf8fce2f275033d;hpb=c7ae0d343bfe168975e01ca4f1026dd52a7f044d diff --git a/extras/collect/collect.c b/extras/collect/collect.c index 0a852f2db..14184a5e0 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; @@ -271,7 +271,18 @@ static int missing(int fd) if (him->state == STATE_NONE) { ret++; } else { - sprintf(buf, "%s ", him->name); + while (strlen(him->name)+1 >= bufsize) { + char *tmpbuf; + + bufsize = bufsize << 1; + 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)); } }