mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-23 19:05:37 +00:00
transfused: fix usage msg, remove syslog, use start-stop-daemon logging
Signed-off-by: David Sheets <david.sheets@docker.com>
This commit is contained in:
parent
224bbcea63
commit
58ded96b29
@ -4,7 +4,6 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <syslog.h>
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -60,26 +59,17 @@ typedef struct {
|
|||||||
} copy_thread_state;
|
} copy_thread_state;
|
||||||
|
|
||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
#ifdef SYS_gettid
|
|
||||||
pid_t gettid() {
|
pid_t gettid() {
|
||||||
return syscall(SYS_gettid);
|
return syscall(SYS_gettid);
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
#error "SYS_gettid not defined"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void die(int exit_code, const char * perror_arg, const char * fmt, ...) {
|
void die(int exit_code, const char * perror_arg, const char * fmt, ...) {
|
||||||
va_list argp;
|
va_list argp;
|
||||||
int in_errno = errno;
|
|
||||||
va_start(argp, fmt);
|
va_start(argp, fmt);
|
||||||
vsyslog(LOG_CRIT, fmt, argp);
|
vfprintf(stderr, fmt, argp);
|
||||||
va_end(argp);
|
va_end(argp);
|
||||||
if (perror_arg != NULL) {
|
if (perror_arg != NULL) perror(perror_arg);
|
||||||
if (*perror_arg != 0)
|
|
||||||
syslog(LOG_CRIT, "%s: %s", perror_arg, strerror(in_errno));
|
|
||||||
else
|
|
||||||
syslog(LOG_CRIT, "%s", strerror(in_errno));
|
|
||||||
}
|
|
||||||
exit(exit_code);
|
exit(exit_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -297,7 +287,7 @@ int get_fuse_sock(char * fusermount, char *const optv[]) {
|
|||||||
if (WEXITSTATUS(status))
|
if (WEXITSTATUS(status))
|
||||||
die(1, NULL, "fusermount exited with code %d\n", WEXITSTATUS(status));
|
die(1, NULL, "fusermount exited with code %d\n", WEXITSTATUS(status));
|
||||||
|
|
||||||
if (debug) syslog(LOG_DEBUG, "about to recv_fd from fusermount");
|
if (debug) fprintf(stderr, "about to recv_fd from fusermount\n");
|
||||||
|
|
||||||
fd = recv_fd(fuse_socks[1]);
|
fd = recv_fd(fuse_socks[1]);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
@ -454,7 +444,7 @@ void perform_syscall(uint8_t syscall, char path[]) {
|
|||||||
die(1, NULL, "Unknown event syscall %" PRIu8, syscall);
|
die(1, NULL, "Unknown event syscall %" PRIu8, syscall);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r != 0) syslog(LOG_INFO, "Event %s error: %s", name, strerror(errno));
|
if (r != 0) fprintf(stderr, "Event %s error: %s", name, strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
void * event_thread(void * connection_ptr) {
|
void * event_thread(void * connection_ptr) {
|
||||||
@ -486,11 +476,11 @@ void * event_thread(void * connection_ptr) {
|
|||||||
|
|
||||||
event_len = (int) ntohs(*((uint16_t *) buf));
|
event_len = (int) ntohs(*((uint16_t *) buf));
|
||||||
|
|
||||||
if (debug) syslog(LOG_DEBUG, "read %d bytes from connection %ld",
|
if (debug) fprintf(stderr, "read %d bytes from connection %ld\n",
|
||||||
read_count, connection->id);
|
read_count, connection->id);
|
||||||
|
|
||||||
if (read_count != event_len) {
|
if (read_count != event_len) {
|
||||||
syslog(LOG_ERR, "event thread: only read %d of %d",
|
fprintf(stderr, "event thread: only read %d of %d\n",
|
||||||
read_count, event_len);
|
read_count, event_len);
|
||||||
|
|
||||||
msg = must_malloc("event hex", read_count * 2 + 1);
|
msg = must_malloc("event hex", read_count * 2 + 1);
|
||||||
@ -498,7 +488,7 @@ void * event_thread(void * connection_ptr) {
|
|||||||
sprintf(((char *) msg) + (i * 2),"%02x",(int) (((char *) buf)[i]));
|
sprintf(((char *) msg) + (i * 2),"%02x",(int) (((char *) buf)[i]));
|
||||||
}
|
}
|
||||||
((char *) msg)[read_count * 2] = 0;
|
((char *) msg)[read_count * 2] = 0;
|
||||||
syslog(LOG_ERR, "message: %s", (char *) msg);
|
fprintf(stderr, "message: %s\n", (char *) msg);
|
||||||
free(msg);
|
free(msg);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
@ -571,7 +561,10 @@ void parse_parameters(int argc, char * argv[], parameters * params) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errflg) die(2, NULL, usage);
|
if (errflg) {
|
||||||
|
fprintf(stderr, "%s", usage);
|
||||||
|
exit(2);
|
||||||
|
}
|
||||||
|
|
||||||
if (params->pidfile != NULL && access(params->pidfile, W_OK))
|
if (params->pidfile != NULL && access(params->pidfile, W_OK))
|
||||||
if (errno != ENOENT)
|
if (errno != ENOENT)
|
||||||
@ -636,7 +629,7 @@ void process_events(char * events_path, int events, parameters * params) {
|
|||||||
// TODO: this is probably the 9p server's fault due to
|
// TODO: this is probably the 9p server's fault due to
|
||||||
// not dropping the read 0 to force short read if
|
// not dropping the read 0 to force short read if
|
||||||
// the real read is flushed
|
// the real read is flushed
|
||||||
syslog(LOG_WARNING, "read 0 from event stream %s", events_path);
|
fprintf(stderr, "read 0 from event stream %s\n", events_path);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -650,7 +643,7 @@ void process_events(char * events_path, int events, parameters * params) {
|
|||||||
conn_id = strtol(buf + 1, NULL, 10);
|
conn_id = strtol(buf + 1, NULL, 10);
|
||||||
if (errno) die(1, "failed", "Connection id of string '%s'", buf);
|
if (errno) die(1, "failed", "Connection id of string '%s'", buf);
|
||||||
|
|
||||||
if (debug) syslog(LOG_DEBUG, "handle connection %ld", conn_id);
|
if (debug) fprintf(stderr, "handle connection %ld\n", conn_id);
|
||||||
|
|
||||||
conn = (connection_state *) must_malloc("connection state",
|
conn = (connection_state *) must_malloc("connection state",
|
||||||
sizeof(connection_state));
|
sizeof(connection_state));
|
||||||
@ -679,7 +672,7 @@ void process_events(char * events_path, int events, parameters * params) {
|
|||||||
die(1, "", "Couldn't detach thread for %s connection '%ld': ",
|
die(1, "", "Couldn't detach thread for %s connection '%ld': ",
|
||||||
connection_type, conn_id);
|
connection_type, conn_id);
|
||||||
|
|
||||||
if (debug) syslog(LOG_DEBUG, "thread spawned");
|
if (debug) fprintf(stderr, "thread spawned\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -688,8 +681,6 @@ int main(int argc, char * argv[]) {
|
|||||||
parameters params;
|
parameters params;
|
||||||
char * events_path;
|
char * events_path;
|
||||||
|
|
||||||
openlog(argv[0], LOG_CONS, LOG_DAEMON);
|
|
||||||
|
|
||||||
parse_parameters(argc, argv, ¶ms);
|
parse_parameters(argc, argv, ¶ms);
|
||||||
setup_debug();
|
setup_debug();
|
||||||
|
|
||||||
@ -701,7 +692,7 @@ int main(int argc, char * argv[]) {
|
|||||||
events = open(events_path, O_RDONLY | O_CLOEXEC);
|
events = open(events_path, O_RDONLY | O_CLOEXEC);
|
||||||
if (events != -1) process_events(events_path, events, ¶ms);
|
if (events != -1) process_events(events_path, events, ¶ms);
|
||||||
|
|
||||||
syslog(LOG_CRIT, "Failed to open events path %s: %s",
|
fprintf(stderr, "Failed to open events path %s: %s\n",
|
||||||
events_path, strerror(errno));
|
events_path, strerror(errno));
|
||||||
free(events_path);
|
free(events_path);
|
||||||
return 1;
|
return 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user