diff options
Diffstat (limited to 'multipart-replace-http-server.c')
-rw-r--r-- | multipart-replace-http-server.c | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/multipart-replace-http-server.c b/multipart-replace-http-server.c index d4f0cd3..29b0ff5 100644 --- a/multipart-replace-http-server.c +++ b/multipart-replace-http-server.c @@ -27,21 +27,30 @@ struct httpfile *filev = NULL; struct reader_thread_args { struct multipart_replace_stream *stream; int fd; + const char *filename; const char *boundary; }; void *reader_thread(void *args_anon) { - pthread_setname_np(pthread_self(), "reader"); struct reader_thread_args *args = args_anon; + + char *name = alloca(strlen("read ")+strlen(args->filename)+1); + strcpy(name, "read "); + strcpy(&name[strlen("read ")], args->filename); + pthread_setname_np(pthread_self(), name); + debug("starting thread: %s", name); + multipart_replace_reader(args->stream, args->fd, args->boundary); - error(EXIT_FAILURE, 0, "multipart_replace stream ended"); + sleep(5); + error(EXIT_FAILURE, 0, "multipart_replace stream ended: %s", args->filename); return NULL; } -void start_multipart_replace_reader(struct multipart_replace_stream *s, int fd, const char *boundary) { +void start_multipart_replace_reader(struct multipart_replace_stream *s, int fd, const char *filename, const char *boundary) { struct reader_thread_args *args = xrealloc(NULL, sizeof(struct reader_thread_args)); args->stream = s; args->fd = fd; + args->filename = filename; args->boundary = boundary; pthread_t thread; pthread_create(&thread, NULL, reader_thread, args); @@ -63,7 +72,7 @@ void file_add(const char *filename) { strncpy(filev[filec-1].name, shortname, sizeof(filev[filec-1].name)); log("added file #%zd: %s", filec-1, filev[filec-1].name); filev[filec-1].stream = stream; - start_multipart_replace_reader(stream, fd, "ffserver" /* FIXME */); + start_multipart_replace_reader(stream, fd, filev[filec-1].name, "ffserver" /* FIXME */); } struct multipart_replace_stream *file_get(const char *filename) { @@ -282,6 +291,16 @@ void cleanup() { sleep(5); /* work around systemd bug dropping log messages */ } +pthread_t main_thread; + +void progname() { + char threadname[16]; + if (pthread_self() != main_thread && pthread_getname_np(pthread_self(), threadname, sizeof(threadname)) == 0) + fprintf(stderr, "%s:%s: ", program_invocation_name, threadname); + else + fprintf(stderr, "%s: ", program_invocation_name); +} + int main(int argc, char *argv[]) { if (argc >=2 && strcmp(argv[1], "-h") == 0) { usage(); @@ -293,6 +312,8 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; } + main_thread = pthread_self(); + error_print_progname = progname; atexit(cleanup); int sock = sockstream_listen(argv[1], argv[2]); |