compile fixes
[ltt-control.git] / ltt / branches / poly / lttd / lttd.c
index 737822e168d533b0a9d5ad0b8434aa1648d036ec..4f5f4bc421d19d27a24b273d028a7bf53b5641ea 100644 (file)
@@ -35,7 +35,7 @@
 /* Get the next sub buffer that can be read. */
 #define RELAYFS_GET_SUBBUF        _IOR(0xF4, 0x00,__u32)
 /* Release the oldest reserved (by "get") sub buffer. */
-#define RELAYFS_PUT_SUBBUF        _IO(0xF4, 0x01)
+#define RELAYFS_PUT_SUBBUF        _IOW(0xF4, 0x01,__u32)
 /* returns the number of sub buffers in the per cpu channel. */
 #define RELAYFS_GET_N_SUBBUFS     _IOR(0xF4, 0x02,__u32)
 /* returns the size of the sub buffers. */
@@ -67,7 +67,6 @@ static char *trace_name = NULL;
 static char *channel_name = NULL;
 static int     daemon_mode = 0;
 static int     append_mode = 0;
-static int     sig_parent = 0;
 volatile static int    quit_program = 0;       /* For signal handler */
 
 /* Args :
@@ -76,7 +75,7 @@ volatile static int   quit_program = 0;       /* For signal handler */
  * -c directory                Root directory of the relayfs trace channels.
  * -d                          Run in background (daemon).
  * -a                                                  Trace append mode.
- * -s                                                  Send SIGIO to parent when ready for IO.
+ * -s                                                  Send SIGUSR1 to parent when ready for IO.
  */
 void show_arguments(void)
 {
@@ -87,7 +86,6 @@ void show_arguments(void)
        printf("-c directory  Root directory of the relayfs trace channels.\n");
        printf("-d            Run in background (daemon).\n");
        printf("-a            Append to an possibly existing trace.\n");
-       printf("-s            Send SIGIO to parent when ready for IO.\n");
        printf("\n");
 }
 
@@ -133,9 +131,6 @@ int parse_arguments(int argc, char **argv)
                                        case 'a':
                                                append_mode = 1;
                                                break;
-                                       case 's':
-                                               sig_parent = 1;
-                                               break;
                                        default:
                                                printf("Invalid argument '%s'.\n", argv[argn]);
                                                printf("\n");
@@ -209,9 +204,7 @@ int open_channel_trace_pairs(char *subchannel_name, char *subtrace_name,
        printf("Creating trace subdirectory %s\n", subtrace_name);
        ret = mkdir(subtrace_name, S_IRWXU|S_IRWXG|S_IRWXO);
        if(ret == -1) {
-               if(errno == EEXIST && append_mode) {
-                       printf("Appending to directory %s as resquested\n", subtrace_name);
-               } else {
+               if(errno != EEXIST) {
                        perror(subtrace_name);
       open_ret = -1;
                        goto end;
@@ -304,13 +297,13 @@ end:
 
 int read_subbuffer(struct fd_pair *pair)
 {
-       unsigned int    subbuf_index;
+       unsigned int    consumed_old;
        int err, ret;
 
 
        err = ioctl(pair->channel, RELAYFS_GET_SUBBUF, 
-                                                               &subbuf_index);
-       printf("index : %u\n", subbuf_index);
+                                                               &consumed_old);
+       printf("cookie : %u\n", consumed_old);
        if(err != 0) {
                perror("Error in reserving sub buffer");
                ret = -EPERM;
@@ -318,7 +311,8 @@ int read_subbuffer(struct fd_pair *pair)
        }
        
        err = TEMP_FAILURE_RETRY(write(pair->trace,
-                               pair->mmap + (subbuf_index * pair->subbuf_size),
+                               pair->mmap 
+                                       + (consumed_old & ((pair->n_subbufs * pair->subbuf_size)-1)),
                                pair->subbuf_size));
 
        if(err < 0) {
@@ -329,10 +323,16 @@ int read_subbuffer(struct fd_pair *pair)
 
 
 write_error:
-       err = ioctl(pair->channel, RELAYFS_PUT_SUBBUF);
+       err = ioctl(pair->channel, RELAYFS_PUT_SUBBUF, &consumed_old);
        if(err != 0) {
-               perror("Error in unreserving sub buffer");
-               ret = -EPERM;
+               if(errno == -EFAULT) {
+                       perror("Error in unreserving sub buffer");
+                       ret = -EFAULT;
+               } else if(errno == -EIO) {
+                       perror("Reader has been pushed by the writer, last subbuffer corrupted.");
+                       /* FIXME : we may delete the last written buffer if we wish. */
+                       ret = -EIO;
+               }
                goto get_error;
        }
 
@@ -412,9 +412,6 @@ int read_channels(struct channel_trace_fd *fd_pairs)
                pollfd[i].events = POLLIN|POLLPRI;
        }
 
-       /* Signal the parent that ready for IO */
-       if(sig_parent) kill(getppid(), SIGIO);
-
        while(1) {
                high_prio = 0;
                num_hup = 0; 
@@ -515,7 +512,6 @@ void close_channel_trace_pairs(struct channel_trace_fd *fd_pairs)
 int main(int argc, char ** argv)
 {
        int ret;
-       pid_t pid;
        struct channel_trace_fd fd_pairs = { NULL, 0 };
        struct sigaction act;
        
@@ -528,18 +524,13 @@ int main(int argc, char ** argv)
        show_info();
 
        if(daemon_mode) {
-               pid = fork();
-               
-               if(pid > 0) {
-                       /* parent */
-                       return 0;
-               } else if(pid < 0) {
-                       /* error */
-                       printf("An error occured while forking.\n");
-                       return -1;
-               }
-               /* else, we are the child, continue... */
-       }
+               ret = daemon(0, 0);
+    
+    if(ret == -1) {
+      perror("An error occured while daemonizing.");
+      exit(-1);
+    }
+  }
 
        /* Connect the signal handlers */
        act.sa_handler = handler;
This page took 0.025101 seconds and 4 git commands to generate.