Added p7servtest, made manpages optional
This commit is contained in:
parent
b25d989d1d
commit
1d45aa0e34
41
Makefile
41
Makefile
|
@ -207,12 +207,33 @@ $(eval $(call make-installbinary-rule,$(bin))))
|
|||
$(MANDIR)/man1:
|
||||
$(call bcmd,mkdir,$@,$(MD) $@)
|
||||
|
||||
# Make-A-Manpage
|
||||
# Check if binaries have a manpage
|
||||
define check-manpage
|
||||
BINMAN_$1 := $(shell test -f $(DOCDIR)/$1.1.txt && echo y)
|
||||
endef
|
||||
$(foreach bin,$(BINARIES),\
|
||||
$(eval $(call check-manpage,$(bin))))
|
||||
|
||||
# Binary manpages related rules
|
||||
define make-manpage-rule
|
||||
$(MANDIR)/man1/$1.%: $(DOCDIR)/$1.1.txt | $(MANDIR)/man1
|
||||
$(call bcmd,a2x,$$<,$(A2X) -f manpage -D $$| $$< 2>/dev/null)
|
||||
all-doc-$1: $(if $(BINMAN_$1),$(MANDIR)/man1/$1.1)
|
||||
|
||||
all-doc-$1: $(MANDIR)/man1/$1.1
|
||||
install-doc-$1: all-doc-$1
|
||||
$(if $(BINMAN_$1),\
|
||||
$(call imsg,Installing $1 manpage))
|
||||
$(if $(BINMAN_$1),\
|
||||
$(call qcmd,$(INSTALL) -m 755 -d "$(IMANDIR)/man1"))
|
||||
$(if $(BINMAN_$1),$(call qcmd,$(INSTALL) -m 644 -t "$(IMANDIR)/man1" \
|
||||
$(MANDIR)/man1/$1.1))
|
||||
$(if $(BINMAN_$1),\
|
||||
$(call qcmd,$(GZIP) "$(IMANDIR)/man1/$1.1"))
|
||||
uninstall-doc-$1:
|
||||
$(if $(BINMAN_$1),\
|
||||
$(call rmsg,Removing $1 manpage))
|
||||
$(if $(BINMAN_$1),\
|
||||
$(call qcmd,$(RM) "$(IMANDIR)/man1/$1.1*"))
|
||||
endef
|
||||
$(foreach bin,$(BINARIES),\
|
||||
$(eval $(call make-manpage-rule,$(bin))))
|
||||
|
@ -222,22 +243,6 @@ $(eval $(call make-manpage-rule,$(bin))))
|
|||
$(call rmsg,Removing manpages directory.)
|
||||
$(call qcmd,$(RM) -r $(MANDIR))
|
||||
|
||||
# Install a manpage.
|
||||
define make-install-manpage-rule
|
||||
install-doc-$1: $(MANDIR)/man1/$1.1
|
||||
$(call imsg,Installing $1 manpage)
|
||||
$(call qcmd,$(INSTALL) -m 755 -d "$(IMANDIR)/man1")
|
||||
$(call qcmd,$(INSTALL) -m 644 -t "$(IMANDIR)/man1" \
|
||||
$(MANDIR)/man1/$1.1)
|
||||
$(call qcmd,$(GZIP) "$(IMANDIR)/man1/$1.1")
|
||||
|
||||
uninstall-doc-$1:
|
||||
$(call rmsg,Removing $1 manpage)
|
||||
$(call qcmd,$(RM) "$(IMANDIR)/man1/$1.1*")
|
||||
endef
|
||||
$(foreach bin,$(BINARIES), \
|
||||
$(eval $(call make-install-manpage-rule,$(bin))))
|
||||
|
||||
.PHONY: $(foreach bin,$(BINARIES),all-doc-$(bin)) clean-doc
|
||||
.PHONY: $(foreach bin,$(BINARIES),install-doc-$(bin) uninstall-doc-$(bin))
|
||||
# End of file.
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
/* ************************************************************************** */
|
||||
/* _____ _ */
|
||||
/* args.c |_ _|__ _ _| |__ ___ _ _ */
|
||||
/* | Project: p7test | |/ _ \| | | | '_ \ / _ \ | | | */
|
||||
/* | | (_) | |_| | | | | __/ |_| | */
|
||||
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
|
||||
/* Last updated: 2017/01/13 00:52:20 |___/ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "main.h"
|
||||
#include <getopt.h>
|
||||
#define Q(x) #x
|
||||
#define QUOTE(x) Q(x)
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Help and version messages */
|
||||
/* ************************************************************************** */
|
||||
/* Version message */
|
||||
static const char version_message[] =
|
||||
QUOTE(BIN) " v" QUOTE(VERSION) " (licensed under GPLv2)\n"
|
||||
"Maintained by " QUOTE(MAINTAINER) ".\n"
|
||||
"\n"
|
||||
"This is free software; see the source for copying conditions.\n"
|
||||
"There is NO warranty; not even for MERCHANTABILITY or\n"
|
||||
"FITNESS FOR A PARTICULAR PURPOSE.";
|
||||
|
||||
/* Main help message */
|
||||
static const char help_main[] =
|
||||
"Usage: " QUOTE(BIN) " [--help] [--version]\n"
|
||||
"\n"
|
||||
"General options:\n"
|
||||
" -h, --help Display the help page of the (sub)command and quit.\n"
|
||||
" -v, --version Display the version message and quit.\n"
|
||||
"\n"
|
||||
"Report bugs to " QUOTE(MAINTAINER) ".";
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Main args parsing function */
|
||||
/* ************************************************************************** */
|
||||
/**
|
||||
* parse_args:
|
||||
* Args parsing main function.
|
||||
*
|
||||
* @arg ac the arguments count.
|
||||
* @arg av the arguments values.
|
||||
* @return if execution should stop after this call.
|
||||
*/
|
||||
|
||||
int parse_args(int ac, char **av)
|
||||
{
|
||||
/* define options */
|
||||
const char shopts[] = "hv";
|
||||
const struct option longopts[] = {
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"version", no_argument, NULL, 'v'},
|
||||
{NULL, 0, NULL, 0}
|
||||
};
|
||||
|
||||
/* get all options */
|
||||
int c; opterr = 0;
|
||||
int help = 0, version = 0;
|
||||
while ((c = getopt_long(ac, av, shopts, longopts, NULL)) >= 0) switch (c) {
|
||||
case 'h': help = 1; break;
|
||||
case 'v': version = 1; break;
|
||||
|
||||
case '?': break;
|
||||
}
|
||||
|
||||
/* get parameters */
|
||||
int pc = ac - optind;
|
||||
if (pc) help = 1;
|
||||
|
||||
/* print help or version */
|
||||
if (help) {
|
||||
puts(help_main);
|
||||
return (1);
|
||||
} else if (version) {
|
||||
puts(version_message);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* no problem */
|
||||
return (0);
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
/* ************************************************************************** */
|
||||
/* _____ _ */
|
||||
/* client.c |_ _|__ _ _| |__ ___ _ _ */
|
||||
/* | Project: p7test | |/ _ \| | | | '_ \ / _ \ | | | */
|
||||
/* | | (_) | |_| | | | | __/ |_| | */
|
||||
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
|
||||
/* Last updated: 2017/01/13 01:40:23 |___/ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "main.h"
|
||||
#include <libp7.h>
|
||||
#include <libp7/packetio.h>
|
||||
|
||||
void run_client(int in, int out)
|
||||
{
|
||||
/* make the handle */
|
||||
p7_handle_t *handle = NULL; int err;
|
||||
if ((err = p7_fdinit(&handle, P7_ACTIVE | P7_CHECK | P7_TERM, "client",
|
||||
in, out))) {
|
||||
fprintf(stderr, "Client initialization encountered an error: %s\n",
|
||||
p7_strerror(err));
|
||||
return ;
|
||||
}
|
||||
|
||||
/* change working directory. */
|
||||
p7_send_cmdfls_cwd(handle, "oui", "fls0");
|
||||
|
||||
/* we're done. */
|
||||
p7_exit(handle);
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
/* ************************************************************************** */
|
||||
/* _____ _ */
|
||||
/* main.c |_ _|__ _ _| |__ ___ _ _ */
|
||||
/* | Project: p7test | |/ _ \| | | | '_ \ / _ \ | | | */
|
||||
/* | | (_) | |_| | | | | __/ |_| | */
|
||||
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
|
||||
/* Last updated: 2017/01/13 00:52:18 |___/ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "main.h"
|
||||
#include <unistd.h>
|
||||
#include <libp7.h>
|
||||
|
||||
/**
|
||||
* init:
|
||||
* Let's go baby.
|
||||
*
|
||||
* @arg sin the server input.
|
||||
* @arg sout the server output.
|
||||
* @arg cin the client input.
|
||||
* @arg cout the client output.
|
||||
*/
|
||||
|
||||
static void init(int sin, int sout, int cin, int cout)
|
||||
{
|
||||
/* everybody do the fork */
|
||||
pid_t pid = fork();
|
||||
if (pid == (pid_t)-1)
|
||||
return ;
|
||||
|
||||
/* yay */
|
||||
if (!pid) run_server(sin, sout);
|
||||
else {
|
||||
sleep(1);
|
||||
run_client(cin, cout);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* main:
|
||||
* A handful of feet.
|
||||
*
|
||||
* @arg ac the arguments count.
|
||||
* @arg av the arguments values.
|
||||
* @return the error code (0 if ok).
|
||||
*/
|
||||
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
/* parse the arguments */
|
||||
if (parse_args(ac, av))
|
||||
return (0);
|
||||
|
||||
/* create the pipes */
|
||||
int fds1[2], fds2[2];
|
||||
if (pipe(fds1)) {
|
||||
fprintf(stderr,
|
||||
"Unable to make the first set of pipes (server to client)\n");
|
||||
return (1);
|
||||
}
|
||||
if (pipe(fds2)) {
|
||||
fprintf(stderr,
|
||||
"Unable to make the second set of pipes (client to server)\n");
|
||||
close(fds1[0]);
|
||||
close(fds1[1]);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* initialize. */
|
||||
init(fds1[0], fds2[1], fds2[0], fds1[1]);
|
||||
|
||||
/* everything went well. */
|
||||
return (0);
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
/* ************************************************************************** */
|
||||
/* _____ _ */
|
||||
/* main.h |_ _|__ _ _| |__ ___ _ _ */
|
||||
/* | Project: p7test | |/ _ \| | | | '_ \ / _ \ | | | */
|
||||
/* | | (_) | |_| | | | | __/ |_| | */
|
||||
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
|
||||
/* Last updated: 2017/01/13 01:42:22 |___/ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#ifndef MAIN_H
|
||||
# define MAIN_H
|
||||
# include <stdio.h>
|
||||
|
||||
int parse_args(int ac, char **av);
|
||||
|
||||
void run_server(int in, int out);
|
||||
void run_client(int in, int out);
|
||||
|
||||
#endif /* MAIN_H */
|
|
@ -0,0 +1,94 @@
|
|||
/* ************************************************************************** */
|
||||
/* _____ _ */
|
||||
/* server.c |_ _|__ _ _| |__ ___ _ _ */
|
||||
/* | Project: p7test | |/ _ \| | | | '_ \ / _ \ | | | */
|
||||
/* | | (_) | |_| | | | | __/ |_| | */
|
||||
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
|
||||
/* Last updated: 2017/01/13 01:04:05 |___/ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "main.h"
|
||||
#include <libp7.h>
|
||||
#include <string.h>
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Server callbacks */
|
||||
/* ************************************************************************** */
|
||||
/**
|
||||
* directory_exists:
|
||||
* Check if a directory exists.
|
||||
*
|
||||
* @arg dirname the directory.
|
||||
* @arg devname the devname.
|
||||
*/
|
||||
|
||||
static int directory_exists(const char *dirname)
|
||||
{
|
||||
/* check directory name */
|
||||
if (!strcmp(dirname, "oui"))
|
||||
return (0);
|
||||
else return (p7_error_notfound);
|
||||
}
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Server configuration */
|
||||
/* ************************************************************************** */
|
||||
/* the server information */
|
||||
static p7_server_t server_information = {
|
||||
/* main calculator information */
|
||||
.cpuid = "The CPU ID, wow!",
|
||||
.hwid = "TESTSERV",
|
||||
.product_id = "OMGOMGOMGOMGOMGO",
|
||||
|
||||
/* system configuration */
|
||||
.username = "Cow",
|
||||
|
||||
/* preprogrammed ROM information */
|
||||
.preprog_rom_wiped = 1,
|
||||
|
||||
/* flash ROM and RAM information */
|
||||
.flash_rom_capacity = 8 * 1024 * 1024,
|
||||
.ram_capacity = 256 * 1024,
|
||||
|
||||
/* bootcode information */
|
||||
.bootcode_wiped = 1,
|
||||
|
||||
/* OS information */
|
||||
.os_offset = 0x80000000, .os_size = 0x100000,
|
||||
.os_version = {
|
||||
.major = 2, .minor = 9, .rev = 2201
|
||||
},
|
||||
};
|
||||
|
||||
/* the server filesystems */
|
||||
static p7_filesystem_t server_filesystems[] = {
|
||||
{
|
||||
.name = "fls0",
|
||||
.directory_exists = directory_exists
|
||||
},
|
||||
{NULL}
|
||||
};
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Server functions */
|
||||
/* ************************************************************************** */
|
||||
/**
|
||||
* run_server:
|
||||
* Run the server!
|
||||
*
|
||||
* @arg in the input.
|
||||
* @arg out the output.
|
||||
*/
|
||||
|
||||
void run_server(int in, int out)
|
||||
{
|
||||
p7_handle_t *handle = NULL; int err;
|
||||
if ((err = p7_fdinit(&handle, 0, "server", in, out))) {
|
||||
fprintf(stderr, "Server encountered an error while initializing: %s\n",
|
||||
p7_strerror(err));
|
||||
return ;
|
||||
}
|
||||
|
||||
p7_serve(handle, &server_information, server_filesystems);
|
||||
p7_exit(handle);
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
#!/usr/bin/make -f
|
||||
disable:
|
||||
libs:
|
||||
@echo libp7
|
Reference in New Issue