summaryrefslogtreecommitdiffstats
path: root/libexec
diff options
context:
space:
mode:
authorcharnier <charnier@FreeBSD.org>1997-12-04 07:25:19 +0000
committercharnier <charnier@FreeBSD.org>1997-12-04 07:25:19 +0000
commit4731a2caff98f86c207a8acecc767df0c74c01ec (patch)
treecbec50b042029bc587075c6b0f6d9bb83b1eed71 /libexec
parent4fcce006699cde380a74f12b8f29df9b1f11bad0 (diff)
downloadFreeBSD-src-4731a2caff98f86c207a8acecc767df0c74c01ec.zip
FreeBSD-src-4731a2caff98f86c207a8acecc767df0c74c01ec.tar.gz
Use err(3). Add prototypes. Document that startup scripts are rc.i386 and
rc.conf (enable/disable) not rc.local. Use full pathname in SYNOPSIS section.
Diffstat (limited to 'libexec')
-rw-r--r--libexec/xtend/packet.c9
-rw-r--r--libexec/xtend/status.c13
-rw-r--r--libexec/xtend/user.c18
-rw-r--r--libexec/xtend/xtend.853
-rw-r--r--libexec/xtend/xtend.c60
5 files changed, 92 insertions, 61 deletions
diff --git a/libexec/xtend/packet.c b/libexec/xtend/packet.c
index ec67c94..bdef357 100644
--- a/libexec/xtend/packet.c
+++ b/libexec/xtend/packet.c
@@ -27,10 +27,13 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
- * $Id$
*/
+#ifndef lint
+static const char rcsid[] =
+ "$Id$";
+#endif /* not lint */
+
#include <stdio.h>
#include <sys/time.h>
#include "xtend.h"
@@ -55,6 +58,7 @@ char *X10cmdnames[] = {
* Log a packet and update device status accordingly
*/
+void
logpacket(p)
unsigned char *p;
{
@@ -72,6 +76,7 @@ unsigned char *p;
* in core and on disk.
*/
+void
processpacket(p)
unsigned char *p;
{
diff --git a/libexec/xtend/status.c b/libexec/xtend/status.c
index e527f55..ca85cdce 100644
--- a/libexec/xtend/status.c
+++ b/libexec/xtend/status.c
@@ -27,10 +27,13 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
- * $Id$
*/
+#ifndef lint
+static const char rcsid[] =
+ "$Id$";
+#endif /* not lint */
+
#include <stdio.h>
#include <unistd.h>
#include <sys/param.h>
@@ -39,14 +42,15 @@
#include "xten.h"
#include "paths.h"
+void printstatus __P((FILE *, STATUS *));
+
/*
* Initialize the status table from the status files
*/
+void
initstatus()
{
- int h, i;
-
if(lseek(status, 0, SEEK_SET) != 0) {
fprintf(Log, "%s: Seek error on status file\n", thedate());
return;
@@ -62,6 +66,7 @@ initstatus()
* and notify anyone monitoring those devices.
*/
+void
checkpoint_status()
{
int h, i, k, offset;
diff --git a/libexec/xtend/user.c b/libexec/xtend/user.c
index 1a863af..c9e9e6d 100644
--- a/libexec/xtend/user.c
+++ b/libexec/xtend/user.c
@@ -27,11 +27,17 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
- * $Id: user.c,v 1.5 1997/02/22 14:22:42 peter Exp $
*/
+#ifndef lint
+static const char rcsid[] =
+ "$Id$";
+#endif /* not lint */
+
+#include <ctype.h>
#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
#include <sys/param.h>
#include <sys/time.h>
#include "xtend.h"
@@ -40,15 +46,19 @@
MONENTRY Monitor[MAXMON];
+int find __P((char *, char *[]));
+void printstatus __P((FILE *, STATUS *));
+
/*
* Process a user command
*/
+int
user_command()
{
char h;
char *m;
- int i, k, c, n, error;
+ int i, k, n, error;
char cmd[512], dumppath[MAXPATHLEN+1], pkt[3];
FILE *dumpf;
@@ -137,6 +147,7 @@ user_command()
return(0);
}
+int
find(s, tab)
char *s;
char *tab[];
@@ -149,6 +160,7 @@ char *tab[];
return(-1);
}
+void
printstatus(f, s)
FILE *f;
STATUS *s;
diff --git a/libexec/xtend/xtend.8 b/libexec/xtend/xtend.8
index fe6209b..41a6677 100644
--- a/libexec/xtend/xtend.8
+++ b/libexec/xtend/xtend.8
@@ -27,16 +27,17 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $Id: xtend.8,v 1.6 1997/02/22 14:22:43 peter Exp $
+.\" $Id: xtend.8,v 1.7 1997/06/24 03:52:15 stark Exp $
.\"
.Th XTEND 8 "30 Oct 1993"
.Dd Oct 30, 1993
.Dt XTEND 8
.Os BSD FreeBSD
.Sh NAME
-xtend \- X-10 daemon
-.Sh SYNOPSIS
.Nm xtend
+.Nd X-10 daemon
+.Sh SYNOPSIS
+.Nm /usr/libexec/xtend
.Sh DESCRIPTION
.Nm Xtend
interfaces between user-level programs and the TW523 X-10 controller.
@@ -45,26 +46,29 @@ status of all X-10 devices, and accepts socket connections from user-level
client programs that need to manipulate X-10 devices.
.Pp
When
-.Nm xtend
+.Nm
is started, it forks, releases the controlling terminal, then opens
its log file, where it subsequently records all X-10 activity and
diagnostic messages. It then begins processing packets received from
the TW523 and accepting connections one at a time from clients
-wishing to issue X-10 commands. The usual place to start xtend would
-be from the
-.Pa /etc/rc.local
-startup script.
+wishing to issue X-10 commands.
+.Nm Xtend
+is started from
+.Pa /etc/rc.i386
+startup script if enabled in
+.Pa /etc/rc.conf
+script.
.Pp
Sending
-.Nm xtend
+.Nm
a SIGHUP causes it to close and reopen its log file. This is useful
in shell scripts that rotate the log files to keep them from growing
indefinitely.
If
-.Nm xtend
+.Nm
receives a SIGTERM, it shuts down gracefully and exits.
A SIGPIPE causes
-.Nm xtend
+.Nm
to abort the current client connection.
.Pp
.Nm Xtend
@@ -73,16 +77,16 @@ command is sent by the client, and is acknowledged by a one-line response
from the daemon.
.Pp
.Nm Xtend
-understands four types of commands. The command
+understands four types of commands. The command:
.Bl -tag
.It status H U
.El
.Pp
where H is a single letter house code, and U is a numeric unit code,
causes
-.Nm xtend
+.Nm
to respond with one line of status information about the specified device.
-The command
+The command:
.Bl -tag
.It send H U N
.El
@@ -93,7 +97,7 @@ or a function code (see source file
) for a list, and N is a number indicating the number of times (usually 2)
the packet is to be transmitted without gaps,
causes
-.Nm xtend
+.Nm
to perform the specified X-10 transmission. If the transmission was apparently
successful, a single-line response containing
.B
@@ -102,25 +106,27 @@ is issued, otherwise a single-line response containing
.B
ERROR
is produced.
-The command
+The command:
.Bl -tag
.It dump
.El
.Pp
causes
-.Nm xtend
-to dump the current status of all devices to an ASCII file in the spool
+.Nm
+to dump the current status of all devices to an
+.Tn ASCII
+file in the spool
directory. The response
.B
OK
is issued, regardless of whether the status dump was successful.
-The command
+The command:
.Bl -tag
.It monitor H U
.El
.Pp
causes
-.Nm xtend
+.Nm
to add the current client socket connection to a list of clients that are to
be notified about activity concerning the specified X-10 device.
The single-line acknowledgement
@@ -135,7 +141,7 @@ is returned.
then returns to its normal mode of accepting connections from clients.
However, each subsequent change in the status of the specified device will
cause
-.Nm xtend
+.Nm
to write one line of status information for the device (in the same
format as produced by the
.B
@@ -161,7 +167,8 @@ log file
.It Pa /var/spool/xten/Status
device status file (binary)
.It Pa /var/spool/xten/status.out
-ASCII dump of device status
+.Tn ASCII
+dump of device status
.El
.Sh BUGS
There is currently no timeout on client socket connections, so a hung
@@ -173,4 +180,4 @@ usually no way it can tell when a device has been operated manually.
This is due to the fact that most X-10 devices are not able to
respond to queries about their status.
.Sh AUTHOR
-Eugene W. Stark (stark@cs.sunysb.edu)
+.An Eugene W. Stark Aq stark@cs.sunysb.edu
diff --git a/libexec/xtend/xtend.c b/libexec/xtend/xtend.c
index dd32129..1ffc448 100644
--- a/libexec/xtend/xtend.c
+++ b/libexec/xtend/xtend.c
@@ -27,22 +27,28 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
- * $Id$
*/
+#ifndef lint
+static const char rcsid[] =
+ "$Id$";
+#endif /* not lint */
+
/*
* xtend - X-10 daemon
* Eugene W. Stark (stark@cs.sunysb.edu)
* January 14, 1993
*/
-#include <stdio.h>
-#include <time.h>
+#include <err.h>
+#include <pwd.h>
#include <setjmp.h>
#include <signal.h>
-#include <pwd.h>
-#include <grp.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
#include <sys/param.h>
#include <sys/file.h>
#include <sys/types.h>
@@ -52,6 +58,7 @@
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/un.h>
+#include <grp.h>
#include "xtend.h"
#include "xten.h"
@@ -68,6 +75,13 @@ void onhup(); /* SIGHUP handler */
void onterm(); /* SIGTERM handler */
void onpipe(); /* SIGPIPE handler */
+void checkpoint_status __P((void));
+void initstatus __P((void));
+void logpacket __P((unsigned char *));
+void processpacket __P((unsigned char *));
+int user_command __P((void));
+
+int
main(argc, argv)
int argc;
char *argv[];
@@ -82,28 +96,21 @@ char *argv[];
struct group *gr;
struct stat sb;
int user;
- int fd;
FILE *pidf;
/*
* Make sure we start out running as root
*/
- if(geteuid() != 0) {
- fprintf(stderr, "You must be root to run %s\n", argv[0]);
- exit(1);
- }
+ if(geteuid() != 0)
+ errx(1, "you must be root");
/*
* Find out what UID/GID we are to run as
*/
- if((pw = getpwnam(XTENUNAME)) == NULL) {
- fprintf(stderr, "%s: No such user '%s'\n", argv[0], XTENUNAME);
- exit(1);
- }
- if((gr = getgrnam(XTENGNAME)) == NULL) {
- fprintf(stderr, "%s: No such group '%s'\n", argv[0], XTENGNAME);
- exit(1);
- }
+ if((pw = getpwnam(XTENUNAME)) == NULL)
+ errx(1, "no such user '%s'", XTENUNAME);
+ if((gr = getgrnam(XTENGNAME)) == NULL)
+ errx(1, "no such group '%s'", XTENGNAME);
/*
* Open the log file before doing anything else
@@ -113,16 +120,13 @@ char *argv[];
if(mkdir(logpath, 0755) != -1) {
chown(logpath, pw->pw_uid, gr->gr_gid);
} else {
- fprintf(stderr, "%s: Can't create directory '%s'\n", argv[0], logpath);
- exit(1);
+ errx(1, "can't create directory '%s'", logpath);
}
}
strcat(logpath, "/");
strcat(logpath, X10LOGNAME);
- if((Log = fopen(logpath, "a")) == NULL) {
- fprintf(stderr, "Can't open log file %s\n", logpath);
- exit(1);
- }
+ if((Log = fopen(logpath, "a")) == NULL)
+ errx(1, "can't open log file '%s'", logpath);
chown(logpath, pw->pw_uid, gr->gr_gid);
/*
@@ -334,10 +338,8 @@ void onhup()
strcpy(logpath, X10DIR);
strcat(logpath, "/");
strcat(logpath, X10LOGNAME);
- if((Log = fopen(logpath, "a")) == NULL) {
- fprintf(stderr, "Can't open log file %s\n", logpath);
- exit(1);
- }
+ if((Log = fopen(logpath, "a")) == NULL)
+ errx(1, "can't open log file '%s'", logpath);
longjmp(mainloop, 1);
/* No return */
}
OpenPOWER on IntegriCloud