public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Stefan Rompf <stefan@loplof.de>
Cc: linux-pm@lists.osdl.org
Subject: Re: [PATCH] suspend.c: make sure stdin, stdout and stderr are open
Date: Fri, 24 Mar 2006 23:55:12 +0100	[thread overview]
Message-ID: <200603242355.48702.rjw@sisk.pl> (raw)
In-Reply-To: <200603242136.56180.rjw@sisk.pl>

[-- Attachment #1: Type: text/plain, Size: 1983 bytes --]

On Friday 24 March 2006 21:36, Rafael J. Wysocki wrote:
> On Friday 24 March 2006 20:13, Stefan Rompf wrote:
> > recently I patched my 2.6.16 kernel to use uswsusp. Nice work, but when I 
> > installed /usr/local/sbin/suspend into the Suse 9.3 powermanagement scripts, 
> > I've stumbled over a bad interaction: powersaved closes all filedescriptors 
> > before calling scripts. suspend then opens snapshot and swap device, 
> > allocating file descriptors 0 and 1, but printfs() afterwards. Luckily, I did 
> > not lose any data.

Fortunately it drops the 0, 1 and 2 descriptors afterwards in prepare_console(). :-)

Still this is a bug and has to be fixed.

I've redone your patch a bit, could you please test it?

Rafael

---
 suspend.c |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletion(-)

Index: suspend/suspend.c
===================================================================
--- suspend.orig/suspend.c
+++ suspend/suspend.c
@@ -856,7 +856,7 @@ int main(int argc, char *argv[])
 	struct stat stat_buf;
 	int resume_fd, snapshot_fd, vt_fd, orig_vc = -1, suspend_vc = -1;
 	dev_t resume_dev;
-	int orig_loglevel, ret = 0;
+	int orig_loglevel, ret;
 
 	if (get_config("suspend", argc, argv, PARAM_NO, parameters, resume_dev_name))
 		return EINVAL;
@@ -875,6 +875,18 @@ int main(int argc, char *argv[])
 	if (s2ram != 'y' && s2ram != 'Y')
 		s2ram = 0;
 
+	/* Make sure the 0, 1, 2 descriptors are open before opening the
+	 * snapshot and resume devices
+	 */
+	do {
+		ret = open("/dev/null", O_RDWR);
+		if (ret < 0) {
+			fprintf(stderr, "suspend: Could not open /dev/null\n");
+			return errno;
+		}
+	} while (ret <= 2);
+	close(ret);
+
 	setvbuf(stdout, NULL, _IONBF, 0);
 	setvbuf(stderr, NULL, _IONBF, 0);
 
@@ -898,6 +910,7 @@ int main(int argc, char *argv[])
 	}
 	resume_dev = stat_buf.st_rdev;
 
+	ret = 0;
 	if (stat(snapshot_dev_name, &stat_buf)) {
 		fprintf(stderr, "suspend: Could not stat the snapshot device file\n");
 		ret = ENODEV;

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



  reply	other threads:[~2006-03-24 22:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-24 19:13 [PATCH] suspend.c: make sure stdin, stdout and stderr are open Stefan Rompf
2006-03-24 20:36 ` Rafael J. Wysocki
2006-03-24 22:55   ` Rafael J. Wysocki [this message]
2006-03-25  8:20     ` Stefan Rompf
2006-03-25 10:54       ` Rafael J. Wysocki
2006-04-10  6:58 ` Stefan Seyfried

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200603242355.48702.rjw@sisk.pl \
    --to=rjw@sisk.pl \
    --cc=linux-pm@lists.osdl.org \
    --cc=stefan@loplof.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox