From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id q2KI88Sw020955 for ; Tue, 20 Mar 2012 19:08:08 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApgBAInGaE9KfVK2kGdsb2JhbABEtlwIIgEBAQEJCQ0HFAQjggkBAQEEEgITCwENARsEGgMMBgUYFgEXIxEBBQEcO4doBJlbCowTgnGFKD+IdgEFC41QAQOCP2MElV4Bjkg9hAqBVQ X-IronPort-AV: E=Sophos;i="4.73,619,1325458800"; d="scan'208";a="136991438" Received: from mail-we0-f182.google.com ([74.125.82.182]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 20 Mar 2012 19:08:03 +0100 Received: by wern13 with SMTP id n13so497893wer.27 for ; Tue, 20 Mar 2012 11:08:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:subject:message-id:mail-followup-to:references :mime-version:content-type:content-disposition :content-transfer-encoding:in-reply-to; bh=ANwxKHHiHvyO1+VGDzhHF+NOUEtgiaHS7wS9gqXIgnE=; b=e6E+oHTDq0zaS3WacsWPbS5B8FqLIhZRes7SOvJT/9/xTPt+dOWuX3t8zd4xcMSzAA lX5G1p3CIxGBJTAAGGlXfrdJRlZkcFo/xnmJyeMIMlLgRYmhwgghyWZjzaMzhRhZiknb tfxIH/QDXXUaPEIj/TUzWDsRv16lnJvfENRg3c02IUM+FZVbHdWf9dDoATmZe803UlHn 9zBjdGeKxjhaTyVhZG3KXu/sU/ACu8F5anOsCSXpVSWUKKthwgeeY14bJDM9x/kXRr72 KK6IjNmW7yvYxk4/FVN0qIJopPiwxIg/+4mi6AcMtV3vrjl3MtEkXcxwrKDZKH0iaxn1 f2Kw== Received: by 10.180.85.69 with SMTP id f5mr1910872wiz.18.1332266883140; Tue, 20 Mar 2012 11:08:03 -0700 (PDT) Received: from localhost (197.Red-79-159-35.staticIP.rima-tde.net. [79.159.35.197]) by mx.google.com with ESMTPS id df3sm35763134wib.1.2012.03.20.11.08.01 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 20 Mar 2012 11:08:02 -0700 (PDT) Date: Tue, 20 Mar 2012 19:07:59 +0100 From: Ricardo Catalinas =?iso-8859-1?Q?Jim=E9nez?= To: caml-list@inria.fr Message-ID: <20120320180759.GE935@viper.local> Mail-Followup-To: caml-list@inria.fr References: <20120320175113.GC935@viper.local> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20120320175113.GC935@viper.local> Subject: [Caml-list] Re: Unix.getlogin () fails when stdin is redirected On Tue, Mar 20, 2012 at 06:51:13PM +0100, Ricardo Catalinas Jiménez wrote: > I found out the next issue in this simple code: > > let () = > print_endline "Hello"; > print_endline (Unix.getlogin ()) > > Running in the normal case, with `./a.out' gives: > > Hello > ricardo > > But running like `./a.out > Hello > Fatal error: exception Unix.Unix_error(20, "getlogin", "") > > A simple strace reveals the problem: > > open("/etc/passwd", O_RDONLY|O_CLOEXEC) = 3 > fstat(3, {st_mode=S_IFREG|0644, st_size=509, ...}) = 0 > mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb125554000 > read(3, "root:x:0:0:root:/root:/bin/bash\n"..., 4096) = 509 > read(3, "", 4096) = 0 > close(3) = 0 > munmap(0x7fb125554000, 4096) = 0 > -> ioctl(0, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x7fff12682c98) = -1 ENOTTY (Inappropriate ioctl for device) > write(2, "Fatal error: exception Unix.Unix"..., 59) = 59 > exit_group(2) = ? Someone knew the answer, man 3 getlogin reads: Note that glibc does not follow the POSIX specification and uses stdin instead of /dev/tty. A bug. (Other recent systems, like SunOS 5.8 and HP-UX 11.11 and FreeBSD 4.8 all return the login name also when stdin is redirected.) Regards -- Ricardo (http://r.untroubled.be/)