check for errors from pthread_create()

This commit is contained in:
Kent Overstreet 2019-01-13 15:17:03 -05:00
parent 5f7dd4b4b2
commit 1504d4c98a
2 changed files with 18 additions and 11 deletions

View File

@ -21,23 +21,27 @@
static inline int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
{
int i = vsnprintf(buf, size, fmt, args);
ssize_t ssize = size;
int i;
return (i >= ssize) ? (ssize - 1) : i;
i = vsnprintf(buf, size, fmt, args);
if (likely(i < size))
return i;
if (size != 0)
return size - 1;
return 0;
}
static inline int scnprintf(char * buf, size_t size, const char * fmt, ...)
{
ssize_t ssize = size;
va_list args;
int i;
va_list args;
int i;
va_start(args, fmt);
i = vsnprintf(buf, size, fmt, args);
va_end(args);
va_start(args, fmt);
i = vscnprintf(buf, size, fmt, args);
va_end(args);
return (i >= ssize) ? (ssize - 1) : i;
return i;
}
#define printk(...) printf(__VA_ARGS__)

View File

@ -57,6 +57,7 @@ struct task_struct *kthread_create(int (*thread_fn)(void *data),
{
va_list args;
struct task_struct *p = malloc(sizeof(*p));
int ret;
memset(p, 0, sizeof(*p));
@ -71,7 +72,9 @@ struct task_struct *kthread_create(int (*thread_fn)(void *data),
atomic_set(&p->usage, 1);
init_completion(&p->exited);
pthread_create(&p->thread, NULL, kthread_start_fn, p);
ret = pthread_create(&p->thread, NULL, kthread_start_fn, p);
if (ret)
die("pthread_create error %s", strerror(ret));
pthread_setname_np(p->thread, p->comm);
return p;
}