3 * Linux Trace Toolkit Daemon
5 * This is a simple daemon that reads a few relay+debugfs channels and save
8 * CPU hot-plugging is supported using inotify.
11 * Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
24 #include <sys/types.h>
34 #include <sys/syscall.h>
36 #include <asm/ioctls.h>
38 #include <linux/version.h>
41 #include <asm/ioctl.h>
42 #include <asm/types.h>
44 /* Get the next sub buffer that can be read. */
45 #define RELAY_GET_SB _IOR(0xF5, 0x00,__u32)
46 /* Release the oldest reserved (by "get") sub buffer. */
47 #define RELAY_PUT_SB _IOW(0xF5, 0x01,__u32)
48 /* returns the number of sub buffers in the per cpu channel. */
49 #define RELAY_GET_N_SB _IOR(0xF5, 0x02,__u32)
50 /* returns the size of the current sub buffer. */
51 #define RELAY_GET_SB_SIZE _IOR(0xF5, 0x03, __u32)
52 /* returns the size of data to consume in the current sub-buffer. */
53 #define RELAY_GET_MAX_SB_SIZE _IOR(0xF5, 0x04, __u32)
56 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14)
57 #include <sys/inotify.h>
58 #if 0 /* should now be provided by libc. */
59 /* From the inotify-tools 2.6 package */
60 static inline int inotify_init (void)
62 return syscall (__NR_inotify_init
);
65 static inline int inotify_add_watch (int fd
, const char *name
, __u32 mask
)
67 return syscall (__NR_inotify_add_watch
, fd
, name
, mask
);
70 static inline int inotify_rm_watch (int fd
, __u32 wd
)
72 return syscall (__NR_inotify_rm_watch
, fd
, wd
);
77 static inline int inotify_init (void)
82 static inline int inotify_add_watch (int fd
, const char *name
, __u32 mask
)
87 static inline int inotify_rm_watch (int fd
, __u32 wd
)
98 unsigned int max_sb_size
;
100 pthread_mutex_t mutex
;
103 struct channel_trace_fd
{
104 struct fd_pair
*pair
;
108 struct inotify_watch
{
110 char path_channel
[PATH_MAX
];
111 char path_trace
[PATH_MAX
];
114 struct inotify_watch_array
{
115 struct inotify_watch
*elem
;
119 static __thread
int thread_pipe
[2];
121 struct channel_trace_fd fd_pairs
= { NULL
, 0 };
123 struct inotify_watch_array inotify_watch_array
= { NULL
, 0 };
125 /* protects fd_pairs and inotify_watch_array */
126 pthread_rwlock_t fd_pairs_lock
= PTHREAD_RWLOCK_INITIALIZER
;
129 static char *trace_name
= NULL
;
130 static char *channel_name
= NULL
;
131 static int daemon_mode
= 0;
132 static int append_mode
= 0;
133 static unsigned long num_threads
= 1;
134 volatile static int quit_program
= 0; /* For signal handler */
135 static int dump_flight_only
= 0;
136 static int dump_normal_only
= 0;
137 static int verbose_mode
= 0;
139 #define printf_verbose(fmt, args...) \
142 printf(fmt, ##args); \
147 * -t directory Directory name of the trace to write to. Will be created.
148 * -c directory Root directory of the debugfs trace channels.
149 * -d Run in background (daemon).
150 * -a Trace append mode.
151 * -s Send SIGUSR1 to parent when ready for IO.
153 void show_arguments(void)
155 printf("Please use the following arguments :\n");
157 printf("-t directory Directory name of the trace to write to.\n"
158 " It will be created.\n");
159 printf("-c directory Root directory of the debugfs trace channels.\n");
160 printf("-d Run in background (daemon).\n");
161 printf("-a Append to an possibly existing trace.\n");
162 printf("-N Number of threads to start.\n");
163 printf("-f Dump only flight recorder channels.\n");
164 printf("-n Dump only normal channels.\n");
165 printf("-v Verbose mode.\n");
172 * Parses the command line arguments.
174 * Returns 1 if the arguments were correct, but doesn't ask for program
175 * continuation. Returns -1 if the arguments are incorrect, or 0 if OK.
177 int parse_arguments(int argc
, char **argv
)
183 if(strcmp(argv
[1], "-h") == 0) {
190 switch(argv
[argn
][0]) {
192 switch(argv
[argn
][1]) {
195 trace_name
= argv
[argn
+1];
201 channel_name
= argv
[argn
+1];
213 num_threads
= strtoul(argv
[argn
+1], NULL
, 0);
218 dump_flight_only
= 1;
221 dump_normal_only
= 1;
227 printf("Invalid argument '%s'.\n", argv
[argn
]);
233 printf("Invalid argument '%s'.\n", argv
[argn
]);
240 if(trace_name
== NULL
) {
241 printf("Please specify a trace name.\n");
246 if(channel_name
== NULL
) {
247 printf("Please specify a channel name.\n");
257 printf("Linux Trace Toolkit Trace Daemon " VERSION
"\n");
259 printf("Reading from debugfs directory : %s\n", channel_name
);
260 printf("Writing to trace directory : %s\n", trace_name
);
265 /* signal handling */
267 static void handler(int signo
)
269 printf("Signal %d received : exiting cleanly\n", signo
);
274 int open_buffer_file(char *filename
, char *path_channel
, char *path_trace
,
275 struct channel_trace_fd
*fd_pairs
)
279 struct stat stat_buf
;
281 if(strncmp(filename
, "flight-", sizeof("flight-")-1) != 0) {
282 if(dump_flight_only
) {
283 printf_verbose("Skipping normal channel %s\n",
288 if(dump_normal_only
) {
289 printf_verbose("Skipping flight channel %s\n",
294 printf_verbose("Opening file.\n");
296 fd_pairs
->pair
= realloc(fd_pairs
->pair
,
297 ++fd_pairs
->num_pairs
* sizeof(struct fd_pair
));
299 /* Open the channel in read mode */
300 fd_pairs
->pair
[fd_pairs
->num_pairs
-1].channel
=
301 open(path_channel
, O_RDONLY
| O_NONBLOCK
);
302 if(fd_pairs
->pair
[fd_pairs
->num_pairs
-1].channel
== -1) {
303 perror(path_channel
);
304 fd_pairs
->num_pairs
--;
305 return 0; /* continue */
307 /* Open the trace in write mode, only append if append_mode */
308 ret
= stat(path_trace
, &stat_buf
);
311 printf_verbose("Appending to file %s as requested\n",
314 fd_pairs
->pair
[fd_pairs
->num_pairs
-1].trace
=
315 open(path_trace
, O_WRONLY
,
316 S_IRWXU
|S_IRWXG
|S_IRWXO
);
317 if(fd_pairs
->pair
[fd_pairs
->num_pairs
-1].trace
== -1) {
320 close(fd_pairs
->pair
[fd_pairs
->num_pairs
-1].channel
);
321 fd_pairs
->num_pairs
--;
324 ret
= lseek(fd_pairs
->pair
[fd_pairs
->num_pairs
-1].trace
,
329 close(fd_pairs
->pair
[fd_pairs
->num_pairs
-1].channel
);
330 close(fd_pairs
->pair
[fd_pairs
->num_pairs
-1].trace
);
331 fd_pairs
->num_pairs
--;
335 printf("File %s exists, cannot open. Try append mode.\n", path_trace
);
337 close(fd_pairs
->pair
[fd_pairs
->num_pairs
-1].channel
);
338 fd_pairs
->num_pairs
--;
342 if(errno
== ENOENT
) {
343 fd_pairs
->pair
[fd_pairs
->num_pairs
-1].trace
=
344 open(path_trace
, O_WRONLY
|O_CREAT
|O_EXCL
,
345 S_IRWXU
|S_IRWXG
|S_IRWXO
);
346 if(fd_pairs
->pair
[fd_pairs
->num_pairs
-1].trace
== -1) {
349 close(fd_pairs
->pair
[fd_pairs
->num_pairs
-1].channel
);
350 fd_pairs
->num_pairs
--;
359 int open_channel_trace_pairs(char *subchannel_name
, char *subtrace_name
,
360 struct channel_trace_fd
*fd_pairs
, int *inotify_fd
,
361 struct inotify_watch_array
*iwatch_array
)
363 DIR *channel_dir
= opendir(subchannel_name
);
364 struct dirent
*entry
;
365 struct stat stat_buf
;
367 char path_channel
[PATH_MAX
];
368 int path_channel_len
;
369 char *path_channel_ptr
;
370 char path_trace
[PATH_MAX
];
372 char *path_trace_ptr
;
375 if(channel_dir
== NULL
) {
376 perror(subchannel_name
);
381 printf_verbose("Creating trace subdirectory %s\n", subtrace_name
);
382 ret
= mkdir(subtrace_name
, S_IRWXU
|S_IRWXG
|S_IRWXO
);
384 if(errno
!= EEXIST
) {
385 perror(subtrace_name
);
391 strncpy(path_channel
, subchannel_name
, PATH_MAX
-1);
392 path_channel_len
= strlen(path_channel
);
393 path_channel
[path_channel_len
] = '/';
395 path_channel_ptr
= path_channel
+ path_channel_len
;
397 strncpy(path_trace
, subtrace_name
, PATH_MAX
-1);
398 path_trace_len
= strlen(path_trace
);
399 path_trace
[path_trace_len
] = '/';
401 path_trace_ptr
= path_trace
+ path_trace_len
;
404 iwatch_array
->elem
= realloc(iwatch_array
->elem
,
405 ++iwatch_array
->num
* sizeof(struct inotify_watch
));
407 printf_verbose("Adding inotify for channel %s\n", path_channel
);
408 iwatch_array
->elem
[iwatch_array
->num
-1].wd
= inotify_add_watch(*inotify_fd
, path_channel
, IN_CREATE
);
409 strcpy(iwatch_array
->elem
[iwatch_array
->num
-1].path_channel
, path_channel
);
410 strcpy(iwatch_array
->elem
[iwatch_array
->num
-1].path_trace
, path_trace
);
411 printf_verbose("Added inotify for channel %s, wd %u\n",
412 iwatch_array
->elem
[iwatch_array
->num
-1].path_channel
,
413 iwatch_array
->elem
[iwatch_array
->num
-1].wd
);
416 while((entry
= readdir(channel_dir
)) != NULL
) {
418 if(entry
->d_name
[0] == '.') continue;
420 strncpy(path_channel_ptr
, entry
->d_name
, PATH_MAX
- path_channel_len
);
421 strncpy(path_trace_ptr
, entry
->d_name
, PATH_MAX
- path_trace_len
);
423 ret
= stat(path_channel
, &stat_buf
);
425 perror(path_channel
);
429 printf_verbose("Channel file : %s\n", path_channel
);
431 if(S_ISDIR(stat_buf
.st_mode
)) {
433 printf_verbose("Entering channel subdirectory...\n");
434 ret
= open_channel_trace_pairs(path_channel
, path_trace
, fd_pairs
,
435 inotify_fd
, iwatch_array
);
436 if(ret
< 0) continue;
437 } else if(S_ISREG(stat_buf
.st_mode
)) {
438 open_ret
= open_buffer_file(entry
->d_name
, path_channel
, path_trace
,
446 closedir(channel_dir
);
452 int read_subbuffer(struct fd_pair
*pair
)
454 unsigned int consumed_old
, len
;
460 err
= ioctl(pair
->channel
, RELAY_GET_SB
, &consumed_old
);
461 printf_verbose("cookie : %u\n", consumed_old
);
464 perror("Reserving sub buffer failed (everything is normal, it is due to concurrency)");
468 err
= TEMP_FAILURE_RETRY(write(pair
->trace
,
470 + (consumed_old
& ((pair
->n_subbufs
* pair
->subbuf_size
)-1)),
475 perror("Error in writing to file");
479 err
= ioctl(pair
->channel
, RELAY_GET_SB_SIZE
, &len
);
482 perror("Getting sub-buffer len failed.");
488 printf_verbose("splice chan to pipe offset %lu\n",
489 (unsigned long)offset
);
490 ret
= splice(pair
->channel
, &offset
, thread_pipe
[1], NULL
,
491 len
, SPLICE_F_MOVE
| SPLICE_F_MORE
);
492 printf_verbose("splice chan to pipe ret %ld\n", ret
);
494 perror("Error in relay splice");
497 ret
= splice(thread_pipe
[0], NULL
, pair
->trace
, NULL
,
498 ret
, SPLICE_F_MOVE
| SPLICE_F_MORE
);
499 printf_verbose("splice pipe to file %ld\n", ret
);
501 perror("Error in file splice");
508 err
= fsync(pair
->trace
);
511 perror("Error in writing to file");
517 err
= ioctl(pair
->channel
, RELAY_PUT_SB
, &consumed_old
);
520 if(errno
== EFAULT
) {
521 perror("Error in unreserving sub buffer\n");
522 } else if(errno
== EIO
) {
523 /* Should never happen with newer LTTng versions */
524 perror("Reader has been pushed by the writer, last sub-buffer corrupted.");
534 int map_channels(struct channel_trace_fd
*fd_pairs
,
535 int idx_begin
, int idx_end
)
540 if(fd_pairs
->num_pairs
<= 0) {
541 printf("No channel to read\n");
545 /* Get the subbuf sizes and number */
547 for(i
=idx_begin
;i
<idx_end
;i
++) {
548 struct fd_pair
*pair
= &fd_pairs
->pair
[i
];
550 ret
= ioctl(pair
->channel
, RELAY_GET_N_SB
, &pair
->n_sb
);
552 perror("Error in getting the number of sub-buffers");
555 ret
= ioctl(pair
->channel
, RELAY_GET_MAX_SB_SIZE
,
558 perror("Error in getting the max sub-buffer size");
561 ret
= pthread_mutex_init(&pair
->mutex
, NULL
); /* Fast mutex */
563 perror("Error in mutex init");
570 for(i
=idx_begin
;i
<idx_end
;i
++) {
571 struct fd_pair
*pair
= &fd_pairs
->pair
[i
];
573 pair
->mmap
= mmap(0, pair
->subbuf_size
* pair
->n_subbufs
, PROT_READ
,
574 MAP_SHARED
, pair
->channel
, 0);
575 if(pair
->mmap
== MAP_FAILED
) {
576 perror("Mmap error");
581 goto end
; /* success */
584 /* munmap only the successfully mmapped indexes */
587 for(j
=idx_begin
;j
<i
;j
++) {
588 struct fd_pair
*pair
= &fd_pairs
->pair
[j
];
591 err_ret
= munmap(pair
->mmap
, pair
->subbuf_size
* pair
->n_subbufs
);
593 perror("Error in munmap");
603 int unmap_channels(struct channel_trace_fd
*fd_pairs
)
609 for(j
=0;j
<fd_pairs
->num_pairs
;j
++) {
610 struct fd_pair
*pair
= &fd_pairs
->pair
[j
];
614 err_ret
= munmap(pair
->mmap
, pair
->subbuf_size
* pair
->n_subbufs
);
616 perror("Error in munmap");
620 err_ret
= pthread_mutex_destroy(&pair
->mutex
);
622 perror("Error in mutex destroy");
631 /* Inotify event arrived.
633 * Only support add file for now.
636 int read_inotify(int inotify_fd
,
637 struct channel_trace_fd
*fd_pairs
,
638 struct inotify_watch_array
*iwatch_array
)
640 char buf
[sizeof(struct inotify_event
) + PATH_MAX
];
641 char path_channel
[PATH_MAX
];
642 char path_trace
[PATH_MAX
];
644 struct inotify_event
*ievent
;
651 len
= read(inotify_fd
, buf
, sizeof(struct inotify_event
) + PATH_MAX
);
655 return 0; /* another thread got the data before us */
657 printf("Error in read from inotify FD %s.\n", strerror(len
));
660 while(offset
< len
) {
661 ievent
= (struct inotify_event
*)&(buf
[offset
]);
662 for(i
=0; i
<iwatch_array
->num
; i
++) {
663 if(iwatch_array
->elem
[i
].wd
== ievent
->wd
&&
664 ievent
->mask
== IN_CREATE
) {
666 "inotify wd %u event mask : %u for %s%s\n",
667 ievent
->wd
, ievent
->mask
,
668 iwatch_array
->elem
[i
].path_channel
,
670 old_num
= fd_pairs
->num_pairs
;
671 strcpy(path_channel
, iwatch_array
->elem
[i
].path_channel
);
672 strcat(path_channel
, ievent
->name
);
673 strcpy(path_trace
, iwatch_array
->elem
[i
].path_trace
);
674 strcat(path_trace
, ievent
->name
);
675 if(ret
= open_buffer_file(ievent
->name
, path_channel
,
676 path_trace
, fd_pairs
)) {
677 printf("Error opening buffer file\n");
680 if(ret
= map_channels(fd_pairs
, old_num
, fd_pairs
->num_pairs
)) {
681 printf("Error mapping channel\n");
687 offset
+= sizeof(*ievent
) + ievent
->len
;
696 * Read the debugfs channels and write them in the paired tracefiles.
698 * @fd_pairs : paired channels and trace files.
700 * returns 0 on success, -1 on error.
702 * Note that the high priority polled channels are consumed first. We then poll
703 * again to see if these channels are still in priority. Only when no
704 * high priority channel is left, we start reading low priority channels.
706 * Note that a channel is considered high priority when the buffer is almost
710 int read_channels(unsigned long thread_num
, struct channel_trace_fd
*fd_pairs
,
711 int inotify_fd
, struct inotify_watch_array
*iwatch_array
)
713 struct pollfd
*pollfd
= NULL
;
716 int num_rdy
, num_hup
;
720 unsigned int old_num
;
728 pthread_rwlock_rdlock(&fd_pairs_lock
);
730 /* Start polling the FD. Keep one fd for inotify */
731 pollfd
= malloc((inotify_fds
+ fd_pairs
->num_pairs
) * sizeof(struct pollfd
));
734 pollfd
[0].fd
= inotify_fd
;
735 pollfd
[0].events
= POLLIN
|POLLPRI
;
738 for(i
=0;i
<fd_pairs
->num_pairs
;i
++) {
739 pollfd
[inotify_fds
+i
].fd
= fd_pairs
->pair
[i
].channel
;
740 pollfd
[inotify_fds
+i
].events
= POLLIN
|POLLPRI
;
742 num_pollfd
= inotify_fds
+ fd_pairs
->num_pairs
;
745 pthread_rwlock_unlock(&fd_pairs_lock
);
751 printf("Press a key for next poll...\n");
753 read(STDIN_FILENO
, &buf
, 1);
754 printf("Next poll (polling %d fd) :\n", num_pollfd
);
757 /* Have we received a signal ? */
758 if(quit_program
) break;
760 num_rdy
= poll(pollfd
, num_pollfd
, -1);
763 perror("Poll error");
767 printf_verbose("Data received\n");
769 switch(pollfd
[0].revents
) {
772 "Error returned in polling inotify fd %d.\n",
777 "Polling inotify fd %d tells it has hung up.\n",
782 "Polling inotify fd %d tells fd is not open.\n",
788 "Polling inotify fd %d : data ready.\n",
791 pthread_rwlock_wrlock(&fd_pairs_lock
);
792 read_inotify(inotify_fd
, fd_pairs
, iwatch_array
);
793 pthread_rwlock_unlock(&fd_pairs_lock
);
799 for(i
=inotify_fds
;i
<num_pollfd
;i
++) {
800 switch(pollfd
[i
].revents
) {
803 "Error returned in polling fd %d.\n",
809 "Polling fd %d tells it has hung up.\n",
815 "Polling fd %d tells fd is not open.\n",
820 pthread_rwlock_rdlock(&fd_pairs_lock
);
821 if(pthread_mutex_trylock(&fd_pairs
->pair
[i
-inotify_fds
].mutex
) == 0) {
823 "Urgent read on fd %d\n",
825 /* Take care of high priority channels first. */
827 /* it's ok to have an unavailable sub-buffer */
828 ret
= read_subbuffer(&fd_pairs
->pair
[i
-inotify_fds
]);
829 if(ret
== EAGAIN
) ret
= 0;
831 ret
= pthread_mutex_unlock(&fd_pairs
->pair
[i
-inotify_fds
].mutex
);
833 printf("Error in mutex unlock : %s\n", strerror(ret
));
835 pthread_rwlock_unlock(&fd_pairs_lock
);
839 /* If every buffer FD has hung up, we end the read loop here */
840 if(num_hup
== num_pollfd
- inotify_fds
) break;
843 for(i
=inotify_fds
;i
<num_pollfd
;i
++) {
844 switch(pollfd
[i
].revents
) {
846 pthread_rwlock_rdlock(&fd_pairs_lock
);
847 if(pthread_mutex_trylock(&fd_pairs
->pair
[i
-inotify_fds
].mutex
) == 0) {
848 /* Take care of low priority channels. */
850 "Normal read on fd %d\n",
852 /* it's ok to have an unavailable subbuffer */
853 ret
= read_subbuffer(&fd_pairs
->pair
[i
-inotify_fds
]);
854 if(ret
== EAGAIN
) ret
= 0;
856 ret
= pthread_mutex_unlock(&fd_pairs
->pair
[i
-inotify_fds
].mutex
);
858 printf("Error in mutex unlock : %s\n", strerror(ret
));
860 pthread_rwlock_unlock(&fd_pairs_lock
);
866 /* Update pollfd array if an entry was added to fd_pairs */
867 pthread_rwlock_rdlock(&fd_pairs_lock
);
868 if((inotify_fds
+ fd_pairs
->num_pairs
) != num_pollfd
) {
869 pollfd
= realloc(pollfd
,
870 (inotify_fds
+ fd_pairs
->num_pairs
) * sizeof(struct pollfd
));
871 for(i
=num_pollfd
-inotify_fds
;i
<fd_pairs
->num_pairs
;i
++) {
872 pollfd
[inotify_fds
+i
].fd
= fd_pairs
->pair
[i
].channel
;
873 pollfd
[inotify_fds
+i
].events
= POLLIN
|POLLPRI
;
875 num_pollfd
= fd_pairs
->num_pairs
+ inotify_fds
;
877 pthread_rwlock_unlock(&fd_pairs_lock
);
879 /* NB: If the fd_pairs structure is updated by another thread from this
880 * point forward, the current thread will wait in the poll without
881 * monitoring the new channel. However, this thread will add the
882 * new channel on next poll (and this should not take too much time
883 * on a loaded system).
885 * This event is quite unlikely and can only occur if a CPU is
886 * hot-plugged while multple lttd threads are running.
898 void close_channel_trace_pairs(struct channel_trace_fd
*fd_pairs
, int inotify_fd
,
899 struct inotify_watch_array
*iwatch_array
)
904 for(i
=0;i
<fd_pairs
->num_pairs
;i
++) {
905 ret
= close(fd_pairs
->pair
[i
].channel
);
906 if(ret
== -1) perror("Close error on channel");
907 ret
= close(fd_pairs
->pair
[i
].trace
);
908 if(ret
== -1) perror("Close error on trace");
910 free(fd_pairs
->pair
);
911 free(iwatch_array
->elem
);
915 void * thread_main(void *arg
)
918 unsigned long thread_num
= (unsigned long)arg
;
920 ret
= pipe(thread_pipe
);
922 perror("Error creating pipe");
925 ret
= read_channels(thread_num
, &fd_pairs
, inotify_fd
, &inotify_watch_array
);
926 close(thread_pipe
[0]); /* close read end */
927 close(thread_pipe
[1]); /* close write end */
936 inotify_fd
= inotify_init();
937 fcntl(inotify_fd
, F_SETFL
, O_NONBLOCK
);
939 if(ret
= open_channel_trace_pairs(channel_name
, trace_name
, &fd_pairs
,
940 &inotify_fd
, &inotify_watch_array
))
942 if (fd_pairs
.num_pairs
== 0) {
943 printf("No channel available for reading, exiting\n");
947 if(ret
= map_channels(&fd_pairs
, 0, fd_pairs
.num_pairs
))
952 close_channel_trace_pairs(&fd_pairs
, inotify_fd
, &inotify_watch_array
);
959 int main(int argc
, char ** argv
)
962 struct sigaction act
;
967 ret
= parse_arguments(argc
, argv
);
969 if(ret
!= 0) show_arguments();
970 if(ret
< 0) return EINVAL
;
971 if(ret
> 0) return 0;
975 /* Connect the signal handlers */
976 act
.sa_handler
= handler
;
978 sigemptyset(&(act
.sa_mask
));
979 sigaddset(&(act
.sa_mask
), SIGTERM
);
980 sigaddset(&(act
.sa_mask
), SIGQUIT
);
981 sigaddset(&(act
.sa_mask
), SIGINT
);
982 sigaction(SIGTERM
, &act
, NULL
);
983 sigaction(SIGQUIT
, &act
, NULL
);
984 sigaction(SIGINT
, &act
, NULL
);
986 if(ret
= channels_init())
993 perror("An error occured while daemonizing.");
998 tids
= malloc(sizeof(pthread_t
) * num_threads
);
999 for(i
=0; i
<num_threads
; i
++) {
1001 ret
= pthread_create(&tids
[i
], NULL
, thread_main
, (void*)i
);
1003 perror("Error creating thread");
1008 for(i
=0; i
<num_threads
; i
++) {
1009 ret
= pthread_join(tids
[i
], &tret
);
1011 perror("Error joining thread");
1014 if((long)tret
!= 0) {
1015 printf("Error %s occured in thread %u\n",
1016 strerror((long)tret
), i
);
1021 ret
= unmap_channels(&fd_pairs
);
1022 close_channel_trace_pairs(&fd_pairs
, inotify_fd
, &inotify_watch_array
);