2 * Copyright (C) 2013 Felix Fietkau <nbd@openwrt.org>
3 * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License version 2.1
7 * as published by the Free Software Foundation
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
16 #include <sys/types.h>
18 #include <sys/reboot.h>
26 #include "plug/hotplug.h"
30 static struct udebug ud
;
31 static struct udebug_buf udb
;
32 static bool udebug_enabled
;
34 static void procd_udebug_vprintf(const char *format
, va_list ap
)
39 udebug_entry_init(&udb
);
40 udebug_entry_vprintf(&udb
, format
, ap
);
41 udebug_entry_add(&udb
);
44 void procd_udebug_printf(const char *format
, ...)
49 procd_udebug_vprintf(format
, ap
);
53 void procd_udebug_set_enabled(bool val
)
55 static const struct udebug_buf_meta meta
= {
57 .format
= UDEBUG_FORMAT_STRING
,
60 if (udebug_enabled
== val
)
66 udebug_buf_free(&udb
);
72 udebug_auto_connect(&ud
, NULL
);
73 udebug_buf_init(&udb
, 1024, 64 * 1024);
74 udebug_buf_add(&ud
, &udb
, &meta
);
79 static int usage(const char *prog
)
81 fprintf(stderr
, "Usage: %s [options]\n"
83 " -s <path> Path to ubus socket\n"
84 " -h <path> run as hotplug daemon\n"
85 " -d <level> Enable debug messages\n"
86 " -S Print messages to stdout\n"
91 int main(int argc
, char **argv
)
94 char *dbglvl
= getenv("DBGLVL");
95 int ulog_channels
= ULOG_KMSG
;
102 while ((ch
= getopt(argc
, argv
, "d:s:h:S")) != -1) {
105 return hotplug_run(optarg
);
107 ubus_socket
= optarg
;
110 debug
= atoi(optarg
);
113 ulog_channels
= ULOG_STDIO
;
116 return usage(argv
[0]);
120 ulog_open(ulog_channels
, LOG_DAEMON
, "procd");
121 ulog_threshold(LOG_DEBUG
+ 1);
126 procd_udebug_set_enabled(true);
128 procd_connect_ubus();