/*
* Scan /dev and find the device name.
*/
-static int findtty(char *res, int rlen, dev_t dev)
+static int findtty(char *res, const char *startdir, size_t rlen, dev_t dev)
{
DIR *dir;
struct dirent *ent;
if (!S_ISCHR(st.st_mode))
continue;
if (st.st_rdev == dev) {
- if (strlen(ent->d_name) + strlen(startdir) + 1 >= rlen) {
+ if ( (strlen(ent->d_name) + strlen(startdir) + 1) >= rlen) {
fprintf(stderr, "bootlogd: console device name too long\n");
closedir(dir);
chdir(olddir);
* See if a console taken from the kernel command line maps
* to a character device we know about, and if we can open it.
*/
-int isconsole(char *s, char *res, int rlen)
+int isconsole(char *s, char *res, size_t rlen)
{
struct consdev *c;
int l, sl, i, fd;
* Find out the _real_ console. Assume that stdin is connected to
* the console device (/dev/console).
*/
-int consolename(char *res, int rlen)
+int consolename(char *res, size_t rlen)
{
#ifdef TIOCGDEV
unsigned int kdev;
#endif
- struct stat st, st2;
+ struct stat st;
+ int n;
+#ifdef __linux__
char buf[256];
char *p;
+ struct stat st2;
int didmount = 0;
- int n, r;
+ int r;
int fd;
+#endif
fstat(0, &st);
if (major(st.st_rdev) != 5 || minor(st.st_rdev) != 1) {
}
#ifdef TIOCGDEV
+# ifndef ENOIOCTLCMD
+# define ENOIOCTLCMD 515
+# endif
if (ioctl(0, TIOCGDEV, &kdev) == 0) {
int r = findtty(res, "/dev", rlen, (dev_t)kdev);
if (0 != r)
perror("bootlogd: /proc/cmdline");
} else {
buf[0] = 0;
- if ((n = read(fd, buf, sizeof(buf) - 1)) >= 0)
+ if ((n = read(fd, buf, sizeof(buf) - 1)) >= 0) {
r = 0;
- else
+ buf[sizeof(buf)-1] = 0; /* enforce null termination */
+ } else
perror("bootlogd: /proc/cmdline");
close(fd);
}
break;
case '\n':
didnl = 1;
- dosync = syncalot;
+ dosync = 1;
break;
case '\t':
line.pos += (line.pos / 8 + 1) * 8;
if (dosync) {
fflush(fp);
- fdatasync(fileno(fp));
+ if (syncalot) {
+ fdatasync(fileno(fp));
+ }
}
outptr += olen;