static int capfile_ctor(struct capfile *capfile, struct capfile_ops const *ops, char const *path, unsigned max_pkts, size_t max_size, unsigned max_secs, size_t cap_len, unsigned rotation, struct timeval const *now) { mutex_ctor_with_type(&capfile->lock, "capfile", PTHREAD_MUTEX_RECURSIVE); capfile->ops = ops; capfile->path = objalloc_strdup(path); if (! capfile->path) goto err1; capfile->max_pkts = max_pkts; capfile->max_size = max_size; capfile->max_secs = max_secs; capfile->cap_len = cap_len; capfile->rotation = rotation; capfile->file_num = 0; capfile->fd = -1; if (0 != capfile->ops->open(capfile, capfile_path(capfile), now)) goto err2; mutex_lock(&capfiles_lock); LIST_INSERT_HEAD(&capfiles, capfile, entry); mutex_unlock(&capfiles_lock); return 0; err2: objfree(capfile->path); err1: mutex_dtor(&capfile->lock); return -1; }
void mutex_ctor(struct mutex *mutex, char const *name) { mutex_ctor_with_type(mutex, name, PTHREAD_MUTEX_ERRORCHECK); }