diff options
author | toni <matzeton@googlemail.com> | 2016-01-04 13:29:11 +0100 |
---|---|---|
committer | toni <matzeton@googlemail.com> | 2016-01-04 21:12:59 +0100 |
commit | ad31e73105e58079c2f4fe85b70b80cd7ae1c76a (patch) | |
tree | 9bbf2fd2791da4881c7d61eee11491e0232d7d9f /src | |
parent | 1ed2e4dd46d9306014e3d75b9dd746cf9622546e (diff) |
blah
Diffstat (limited to 'src')
-rw-r--r-- | src/check/check.c | 36 | ||||
-rw-r--r-- | src/log.c | 19 | ||||
-rw-r--r-- | src/log.h | 8 | ||||
-rw-r--r-- | src/main.c | 14 | ||||
-rw-r--r-- | src/opt.c | 3 |
5 files changed, 64 insertions, 16 deletions
diff --git a/src/check/check.c b/src/check/check.c index bbc22eb..9d28129 100644 --- a/src/check/check.c +++ b/src/check/check.c @@ -4,13 +4,16 @@ #include <fcntl.h> #include <sys/stat.h> #include <sys/wait.h> +#include <semaphore.h> #include <mqueue.h> -#define myassert(x) if ((x)) { ret &= 0xFF; } else { ret &= 0x00; } -static volatile unsigned char ret = 0xFF; +#define myassert(x, emask) if ((x)) { ret &= ret; } else { ret |= emask; } + +static volatile unsigned long long int ret = 0x0; static mqd_t mq_test; static mqd_t mq_recv; +static sem_t *sp_test; static const size_t bufsiz = 256; int main(int argc, char **argv) @@ -32,24 +35,31 @@ int main(int argc, char **argv) m_attr.mq_curmsgs = 0; mq_unlink("/testmq"); - myassert( (mq_test = mq_open( "/testmq", O_NONBLOCK | O_CREAT | O_EXCL | O_RDWR, S_IRWXU | S_IRWXG, &m_attr )) != (mqd_t)-1 ); - myassert( mq_getattr(mq_test, &m_attr) == 0 ); + myassert( (mq_test = mq_open( "/testmq", O_NONBLOCK | O_CREAT | O_EXCL | O_RDWR, S_IRWXU | S_IRWXG, &m_attr )) != (mqd_t)-1, 0x1 ); + myassert( mq_getattr(mq_test, &m_attr) == 0, 0x2 ); strcpy(buf, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVQXYZ"); - myassert( mq_send(mq_test, buf, bufsiz, 0) == 0 ); - myassert( (sz_recv = mq_receive(mq_test, recv, bufsiz, &prio)) > 0 ); + myassert( mq_send(mq_test, buf, bufsiz, 0) == 0, 0x4 ); + myassert( (sz_recv = mq_receive(mq_test, recv, bufsiz, &prio)) > 0, 0x8 ); memset(recv, '\0', bufsiz); if (fork() > 0) { - myassert( (mq_recv = mq_open( "/testmq", O_RDONLY, S_IRWXU | S_IRWXG, &m_attr )) != (mqd_t)-1 ); - myassert( (sz_recv = mq_receive(mq_recv, recv, bufsiz, &prio)) > 0 ); + myassert( (mq_recv = mq_open( "/testmq", O_RDONLY, S_IRWXU | S_IRWXG, &m_attr )) != (mqd_t)-1, 0x10 ); + myassert( (sz_recv = mq_receive(mq_recv, recv, bufsiz, &prio)) > 0, 0x20 ); return ret; } - myassert( mq_send(mq_test, buf, bufsiz, 0) == 0 ); + myassert( mq_send(mq_test, buf, bufsiz, 0) == 0, 0x40 ); wait(&c_stat); - myassert( c_stat == 0xFF ); - myassert( mq_close(mq_test) == 0 ); - myassert( mq_unlink("/testmq") == 0 ); + myassert( c_stat == 0xFF, 0x80 ); + myassert( mq_close(mq_test) == 0, 0x100 ); + myassert( mq_unlink("/testmq") == 0, 0x200 ); + + myassert( sem_unlink("/testsem") == 0, 0x400 ); + myassert( (sp_test = sem_open("/testsem", O_CREAT | O_EXCL, S_IRUSR | S_IWUSR, 0)), 0x800 ); + myassert( sem_post(sp_test) == 0, 0x1000 ); + myassert( sem_wait(sp_test) == 0, 0x1200 ); + myassert( sem_close(sp_test) == 0, 0x1400 ); + myassert( sem_unlink("/testsem") == 0, 0x1800 ); - return ~ret; + return ret; } diff --git a/src/log.c b/src/log.c new file mode 100644 index 0000000..93d6532 --- /dev/null +++ b/src/log.c @@ -0,0 +1,19 @@ +#include <stdio.h> +#include <stdlib.h> + +#include "log.h" + + +static int logfd; + +int log_init(char *file) +{ + logfd = fopen(file, "a+"); + return logfd; +} + +int logs(char *format, ...) +{ + +} + diff --git a/src/log.h b/src/log.h new file mode 100644 index 0000000..7b4affc --- /dev/null +++ b/src/log.h @@ -0,0 +1,8 @@ +#ifndef LOG_H +#define LOG_H 1 + +int log_init(char *file); + +int logs(char *format, ...); + +#endif @@ -73,7 +73,7 @@ run_cryptcreate(char *pass, char *crypt_cmd) char *cmd; if (crypt_cmd == NULL || pass == NULL) return (-1); - asprintf(&cmd, "echo '%s' | %s >/dev/null 2>/dev/null", pass, crypt_cmd); + asprintf(&cmd, "echo '%s' | %s", pass, crypt_cmd); retval = system(cmd); free(cmd); return (retval); @@ -112,7 +112,12 @@ main(int argc, char **argv) } memset(pbuf, '\0', IPC_MQSIZ+1); - parse_cmd(argc, argv); + if ( parse_cmd(argc, argv) != 0 ) + goto error; + if (OPT(CRYPT_CMD).found == 0) { + usage(argv[0]); + goto error; + } if (check_fifo(GETOPT(FIFO_PATH).str) == false) { usage(argv[0]); goto error; @@ -164,7 +169,10 @@ main(int argc, char **argv) break; } } - wait(&c_status); + waitpid(child, &c_status, WNOHANG); + if ( WIFEXITED(c_status) == 0 ) { + wait(&c_status); + } memset(pbuf, '\0', IPC_MQSIZ+1); } else { /* fork error */ @@ -39,6 +39,9 @@ parse_cmd(int argc, char **argv) case 'c': s_OPT(CRYPT_CMD, strdup(optarg)); break; + default: + usage(argv[0]); + return 1; } } return 0; |