This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

utmpname(3) returns interger but man page says void.


Hi,

In glibc 2.7 I found, Man page of utmpname(3) says its prototype as...

             void utmpname(const char *file);

But if we check the source in login/utmpname.c
int
__utmpname (const char *file)
{
....
....
}

This is conflicting one, so man page needs to be fixed.

And utmpname(3) does not reports failure if the file that we pass and
it does not exists.


The testcase is...
$ ls -l utmp1
ls: utmp1: No such file or directory

$ cat test.c
#include <stdio.h>
#include <utmp.h>

int main()
{
      printf("%d\n", utmpname("./utmp1"));
}

$ gcc test.c -o test
$ ./test
0

This intern affecting the other commands like who (1).

$ who ./utmp1
$ echo $?
0

**Even utmp1 file not exists, its exit status is zero.

Fixing the issue in utmp will fix the other dependencies.

Patch to fix the issue
=================
--- utmpname.c.old      2008-06-24 16:36:27.000000000 +0530
+++ utmpname.c  2008-06-24 16:37:12.000000000 +0530
@@ -21,6 +21,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <utmp.h>
+#include <sys/stat.h>

 #include "utmp-private.h"

@@ -39,6 +40,12 @@
 __utmpname (const char *file)
 {
  int result = -1;
+  struct stat buf;
+
+  if (stat(file, &buf) != 0)
+   {
+        return result;
+   }

  __libc_lock_lock (__libc_utmp_lock);


Thanks,
Halesh


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]