4 #include <linux/logger.h>
10 #include <sys/ioctl.h>
11 #include <sys/types.h>
16 #define handle_error_en(en, msg) \
17 do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0)
19 #define BIT(nr) ((1UL) << (nr))
21 void *tstart(void *arg)
24 write(*fd, "child thread msg #1\nchild thread msg #2", 39);
28 int main(int ac, char *av[]) {
30 char *device = "/dev/log_main";
31 char *msg = "The Foo";
33 struct logger_set_tag struct_tag = {
35 .ptr = (uintptr_t)tag,
41 unsigned char prio = 4;
42 unsigned long test_mask = ~0UL;
45 static struct option long_options[] = {
46 {"priority", required_argument, 0, 'p'},
47 {"tag", required_argument, 0, 't'},
48 {"test-mask", required_argument, 0, 'm'},
49 {"device", required_argument, 0, 'd'},
53 c = getopt_long(ac, av, "p:t:m:d:", long_options, NULL);
59 prio = (unsigned char) strtol(optarg, NULL, 10);
65 test_mask = (unsigned char) strtol(optarg, NULL, 16);
68 device = strdup(optarg);
76 fd = open(device, O_WRONLY);
78 if (test_mask & BIT(0)) {
79 vec[0].iov_base = &prio;
81 vec[1].iov_base = tag;
82 vec[1].iov_len = strlen(tag) + 1;
83 vec[2].iov_base = msg;
84 vec[2].iov_len = strlen(msg) + 1;
87 if (test_mask & BIT(1)) {
88 msg = "line #1\nline #2";
89 vec[2].iov_base = msg;
90 vec[2].iov_len = strlen(msg) + 1;
96 ioctl(fd, LOGGER_SET_PRIO, prio);
97 ioctl(fd, LOGGER_SET_TAG, &struct_tag);
99 if (test_mask & BIT(2)) {
101 count = write(fd, "The Foo From STDIO\n", 19);
103 printf("count != 19\n");
105 write(fd, "LINE #1\nLINE #2", 15);
106 write(fd, " CONTINUED\nONCE", 15);
107 write(fd, " AGAIN\n", 7);
110 if (test_mask & BIT(3)) {
115 for (int i = 0; i < 8000; i++)
116 msg[i] = '!' + (i % 95);
118 write(fd, msg, 8000);
120 for (int i = 0; (test_mask & BIT(4)) && i < 40; i++)
121 write(fd, msg, 8000);
123 for (int i = 0; (test_mask & BIT(5)) && i < 8000; i++)
124 write(fd, &msg[i], 1);
130 if (test_mask & BIT(6)) {
134 } else if (child == 0) {
136 printf("child: %d\n", getpid());
137 write(fd, "child 1\n", 8);
139 write(fd, "child 2\n", 8);
143 write(fd, "PARENT\n", 7);
144 printf("PARENT: %d\n", getpid());
148 if (test_mask & BIT(7)) {
149 s = pthread_create(&tid, NULL, &tstart, &fd);
151 handle_error_en(s, "pthread_create");
153 write(fd, "PARENT THREAD\n", 14);
155 s = pthread_join(tid, NULL);
157 handle_error_en(s, "pthread_join");