/* * cleanup_mqueue() - performs all ONE TIME cleanup for this test at * completion or premature exit. * step == -1 means no local resource to remove. */ void cleanup_mqueue(int result, int step, mqd_t mqd) { if (step != NO_STEP) cleanup_resources(step, mqd); tst_exit(); }
/* * child_fn() - Inside container */ int child_fn(void *arg) { pid_t pid, ppid; mqd_t mqd; char buf[5]; /* Set process id and parent pid */ pid = getpid(); ppid = getppid(); if (pid != CHILD_PID || ppid != PARENT_PID) { tst_resm(TBROK, "cinit: pidns is not created"); cleanup_mqueue(TBROK, NO_STEP, 0); } /* Close the appropriate end of pipe */ close(father_to_child[1]); /* Is parent ready to receive a message? */ read(father_to_child[0], buf, 5); if (strcmp(buf, "f:ok")) { tst_resm(TBROK, "cinit: parent did not send the message!"); cleanup_mqueue(TBROK, NO_STEP, 0); } tst_resm(TINFO, "cinit: my father is ready to receive a message"); mqd = ltp_syscall(__NR_mq_open, mqname, O_WRONLY, 0, NULL); if (mqd == (mqd_t) - 1) { tst_resm(TBROK, "cinit: mq_open() failed (%s)", strerror(errno)); cleanup_mqueue(TBROK, NO_STEP, 0); } tst_resm(TINFO, "cinit: mq_open succeeded"); if (mq_send(mqd, MSG, strlen(MSG), MSG_PRIO) == (mqd_t) - 1) { tst_resm(TBROK, "cinit: mq_send() failed (%s)", strerror(errno)); cleanup_mqueue(TBROK, C_STEP_0, mqd); } tst_resm(TINFO, "cinit: mq_send() succeeded"); /* Cleanup and exit */ cleanup_resources(C_STEP_1, mqd); exit(0); }
int busybox_logread(char *pszOutputFile) { int i; FILE *fOut=fopen(pszOutputFile,"w"); if(!fOut) { return 1; } if ( (log_shmid = shmget(KEY_ID, 0, 0)) == -1) { fclose(fOut); return 1; } // Attach shared memory to our char* if ( (buf = shmat(log_shmid, NULL, SHM_RDONLY)) == NULL) { cleanup_resources(); fclose(fOut); return 1; } if ( (log_semid = semget(KEY_ID, 0, 0)) == -1) { cleanup_resources(); fclose(fOut); return 1; } // Suppose atomic memory move i = buf->head; #ifdef CONFIG_FEATURE_LOGREAD_REDUCED_LOCKING char *buf_data; int log_len,j; #endif sem_down(log_semid); //printf("head: %i tail: %i size: %i\n",buf->head,buf->tail,buf->size); if (buf->head == buf->tail || i==buf->tail) { fprintf(fOut,"<empty syslog>\n"); } // Read Memory #ifdef CONFIG_FEATURE_LOGREAD_REDUCED_LOCKING log_len = buf->tail - i; if (log_len < 0) log_len += buf->size; buf_data = (char *)xmalloc(log_len); if (buf->tail < i) { memcpy(buf_data, buf->data+i, buf->size-i); memcpy(buf_data+buf->size-i, buf->data, buf->tail); } else { memcpy(buf_data, buf->data+i, buf->tail-i); } i = buf->tail; #else while ( i != buf->tail) { fprintf(fOut, "%s", buf->data+i); i+= strlen(buf->data+i) + 1; if (i >= buf->size ) i=0; } #endif // release the lock on the log chain sem_up(log_semid); #ifdef CONFIG_FEATURE_LOGREAD_REDUCED_LOCKING for (j=0; j < log_len; j+=strlen(buf_data+j)+1) { fprintf(fOut, "%s", buf_data+j); } free(buf_data); #endif fflush(fOut); if (log_shmid != -1) shmdt(buf); printf("\n httpd.busybox_logread: returning success"); fclose(fOut); return 0; }