summaryrefslogtreecommitdiff
path: root/cmd/service/loadsvc.c
blob: bbd15f8195570f76df91961fcf964169831adbd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/* SPDX-License-Identifier: ISC */
#include "servicecmd.h"

#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>

service_t *loadsvc(const char *directory, const char *filename, int flags)
{
	service_t *svc;
	int dirfd;

	dirfd = open(directory, O_RDONLY | O_DIRECTORY);

	if (dirfd < 0) {
		perror(directory);
		return NULL;
	}

	svc = rdsvc(dirfd, filename, flags);
	close(dirfd);
	return svc;
}