2013-08-07 06:43:55 -04:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
|
|
|
#include <sys/syscall.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
2014-04-12 09:30:56 -04:00
|
|
|
eprintf("usage: %s filename [args...]\n", argv0);
|
2013-08-07 06:43:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
char *buf = NULL, *opts = NULL;
|
2014-02-14 08:52:04 -05:00
|
|
|
size_t blen, plen = 0;
|
2013-08-07 06:43:55 -04:00
|
|
|
int i, fd;
|
|
|
|
ssize_t n;
|
|
|
|
struct stat sb;
|
|
|
|
|
|
|
|
ARGBEGIN {
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
} ARGEND;
|
|
|
|
|
|
|
|
if (argc < 1)
|
|
|
|
usage();
|
|
|
|
|
|
|
|
fd = open(argv[0], O_RDONLY);
|
|
|
|
if (fd < 0)
|
|
|
|
eprintf("open %s:", argv[0]);
|
|
|
|
if (fstat(fd, &sb) < 0)
|
|
|
|
eprintf("stat %s:", argv[0]);
|
|
|
|
blen = sb.st_size;
|
2014-04-30 08:08:16 -04:00
|
|
|
buf = emalloc(blen);
|
2013-08-07 06:43:55 -04:00
|
|
|
|
2014-02-14 08:52:04 -05:00
|
|
|
n = read(fd, buf, blen);
|
|
|
|
if(n < 0 || (size_t)n != blen)
|
2013-08-07 06:43:55 -04:00
|
|
|
eprintf("read:");
|
|
|
|
|
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
|
|
|
|
for (i = 0; i < argc; i++)
|
|
|
|
plen += strlen(argv[i]);
|
|
|
|
if (plen > 0) {
|
|
|
|
plen += argc;
|
2014-04-30 08:08:16 -04:00
|
|
|
opts = ecalloc(1, plen);
|
2013-08-07 06:43:55 -04:00
|
|
|
for (i = 0; i < argc; i++) {
|
|
|
|
strcat(opts, argv[i]);
|
|
|
|
if (i + 1 < argc)
|
|
|
|
strcat(opts, " ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-09 04:52:17 -04:00
|
|
|
if (syscall(__NR_init_module, buf, blen, !opts ? "" : opts) < 0)
|
2013-08-07 06:43:55 -04:00
|
|
|
eprintf("init_module:");
|
|
|
|
|
|
|
|
free(opts);
|
|
|
|
free(buf);
|
2013-10-07 14:11:40 -04:00
|
|
|
return EXIT_SUCCESS;
|
2013-08-07 06:43:55 -04:00
|
|
|
}
|