Merge lp:~jamesodhunt/upstart/kmsg-noctty into lp:upstart

Proposed by James Hunt
Status: Merged
Merged at revision: 1592
Proposed branch: lp:~jamesodhunt/upstart/kmsg-noctty
Merge into: lp:upstart
Diff against target: 76 lines (+37/-14)
2 files modified
ChangeLog (+6/-0)
init/main.c (+31/-14)
To merge this branch: bzr merge lp:~jamesodhunt/upstart/kmsg-noctty
Reviewer Review Type Date Requested Status
St├ęphane Graber Approve
Review via email: mp+202673@code.launchpad.net
To post a comment you must log in.
Revision history for this message
St├ęphane Graber (stgraber) wrote :

Looks good to me.

review: Approve
Revision history for this message
James Hunt (jamesodhunt) wrote :

Thanks for reviewing - merged.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'ChangeLog'
--- ChangeLog 2014-01-17 15:39:55 +0000
+++ ChangeLog 2014-01-22 13:50:27 +0000
@@ -1,3 +1,9 @@
12014-01-22 James Hunt <james.hunt@ubuntu.com>
2
3 * init/main.c: logger_kmsg(): Use open(2) rather than fopen(3) to avoid
4 stealing the console in an container: fopen(3) may not specify
5 O_NOCTTY and Upstart should not own the console (LP: #1263738).
6
12014-01-17 James Hunt <james.hunt@ubuntu.com>72014-01-17 James Hunt <james.hunt@ubuntu.com>
28
3 * init/conf.c:9 * init/conf.c:
410
=== modified file 'init/main.c'
--- init/main.c 2013-11-05 16:15:19 +0000
+++ init/main.c 2014-01-22 13:50:27 +0000
@@ -740,8 +740,12 @@
740logger_kmsg (NihLogLevel priority,740logger_kmsg (NihLogLevel priority,
741 const char *message)741 const char *message)
742{742{
743 int tag;743 int tag;
744 FILE *kmsg;744 int fd;
745 ssize_t ret;
746 size_t remaining = -1;
747 nih_local char *buffer = NULL;
748 char *p;
745749
746 nih_assert (message != NULL);750 nih_assert (message != NULL);
747751
@@ -768,18 +772,31 @@
768 tag = 'd';772 tag = 'd';
769 }773 }
770774
771 kmsg = fopen ("/dev/kmsg", "w");775 fd = open ("/dev/kmsg", O_WRONLY | O_NOCTTY);
772 if (! kmsg)776 if (fd < 0)
773 return -1;777 return -1;
774778
775 if (fprintf (kmsg, "<%c>%s: %s\n", tag, program_name, message) < 0) {779 buffer = nih_sprintf (NULL, "<%c>%s: %s\n", tag, program_name, message);
776 int saved_errno = errno;780 if (! buffer)
777 fclose (kmsg);781 goto out;
778 errno = saved_errno;782
779 return -1;783 p = buffer;
780 }784
781785 remaining = strlen (p);
782 if (fclose (kmsg) < 0)786
787 do {
788 ret = write (fd, p, remaining);
789 if (ret > 0) {
790 p += ret;
791 remaining -= ret;
792 } else if (! ret || (ret < 0 && errno != EINTR)) {
793 close (fd);
794 return -1;
795 }
796 } while (remaining);
797
798out:
799 if (close (fd) < 0)
783 return -1;800 return -1;
784801
785 return 0;802 return 0;

Subscribers

People subscribed via source and target branches