3 Copyright 2005 Stephan Kulow <coolo@kde.org>
4 Copyright 2005 Oswald Buddenhagen <ossi@kde.org>
6 Permission to use, copy, modify, distribute, and sell this software and its
7 documentation for any purpose is hereby granted without fee, provided that
8 the above copyright notice appear in all copies and that both that
9 copyright notice and this permission notice appear in supporting
12 The above copyright notice and this permission notice shall be included
13 in all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 OTHER DEALINGS IN THE SOFTWARE.
23 Except as contained in this notice, the name of a copyright holder shall
24 not be used in advertising or otherwise to promote the sale, use or
25 other dealings in this Software without prior written authorization
26 from the copyright holder.
31 * xdm - display manager daemon
32 * Author: Keith Packard, MIT X Consortium
46 getNull( char ***opts ATTR_UNUSED
, int *def ATTR_UNUSED
, int *cur ATTR_UNUSED
)
52 setNull( const char *opt ATTR_UNUSED
, SdRec
*sdr ATTR_UNUSED
)
58 match( char *obuf
, int *blen
, const char *key
, int klen
)
61 if (memcmp( buf
, key
, klen
) || !isspace( buf
[klen
] ))
64 for (; isspace( *buf
); buf
++);
71 #define GRUB_MENU "/boot/grub/menu.lst"
76 getGrub( char ***opts
, int *def
, int *cur
)
83 if (!grub
&& !(grub
= locate( "grub" )))
88 *opts
= initStrArr( 0 );
90 if (!(f
= fopen( GRUB_MENU
, "r" )))
91 return errno
== ENOENT
? BO_NOMAN
: BO_IO
;
92 while ((len
= fGets( line
, sizeof(line
), f
)) != -1) {
93 for (linp
= line
; isspace( *linp
); linp
++, len
--);
94 if ((ptr
= match( linp
, &len
, "default", 7 )))
96 else if ((ptr
= match( linp
, &len
, "title", 5 ))) {
97 for (; isspace( ptr
[len
- 1] ); len
--);
98 *opts
= addStrArr( *opts
, ptr
, len
);
107 setGrub( const char *opt
, SdRec
*sdr
)
114 if (!(f
= fopen( GRUB_MENU
, "r" )))
115 return errno
== ENOENT
? BO_NOMAN
: BO_IO
;
116 for (i
= 0; (len
= fGets( line
, sizeof(line
), f
)) != -1; )
117 if ((ptr
= match( line
, &len
, "title", 5 ))) {
118 if (!strcmp( ptr
, opt
)) {
121 sdr
->bmstamp
= mTime( GRUB_MENU
);
135 static const char *args
[] = { 0, "--batch", "--no-floppy", 0 };
137 if (sdRec
.bmstamp
!= mTime( GRUB_MENU
) &&
138 setGrub( sdRec
.osname
, &sdRec
) != BO_OK
)
142 if ((f
= pOpen( (char **)args
, 'w', &pid
))) {
143 fprintf( f
, "savedefault --default=%d --once\n", sdRec
.osindex
);
151 getLilo( char ***opts
, int *def
, int *cur
)
154 int cdef
, pid
, len
, ret
= BO_OK
;
155 static const char *args
[5] = { 0, "-w", "-v", "-q", 0 };
156 char buf
[256], next
[256];
158 if (!lilo
&& !(lilo
= locate( "lilo" )))
162 if (!(f
= pOpen( (char **)args
, 'r', &pid
)))
167 if ((len
= fGets( buf
, sizeof(buf
), f
)) == -1) {
171 if (!memcmp( buf
, "Images:", 7 ))
173 #define Ldeflin " Default boot command line:"
174 if (!memcmp( buf
, Ldeflin
, strlen(Ldeflin
) )) {
175 memcpy( next
, buf
+ strlen(Ldeflin
) + 2, len
- strlen(Ldeflin
) - 3 );
176 next
[len
- strlen(Ldeflin
) - 3] = 0;
181 *opts
= initStrArr( 0 );
182 while ((len
= fGets( buf
, sizeof(buf
), f
)) != -1)
183 if (buf
[0] == ' ' && buf
[1] == ' ' && buf
[2] != ' ') {
184 if (buf
[len
- 1] == '*') {
188 for (; buf
[len
- 1] == ' '; len
--);
189 *opts
= addStrArr( *opts
, buf
+ 2, len
- 2 );
190 if (!strcmp( (*opts
)[cdef
], next
))
195 if (pClose( f
, &pid
)) {
204 setLilo( const char *opt
, SdRec
*sdr ATTR_UNUSED
)
207 int def
, cur
, ret
, i
;
209 if ((ret
= getLilo( &opts
, &def
, &cur
)) != BO_OK
)
214 for (i
= 0; opts
[i
]; i
++)
215 if (!strcmp( opts
[i
], opt
))
228 static const char *args
[5] = { 0, "-w", "-R", 0, 0 };
231 args
[3] = sdRec
.osname
;
232 runAndWait( (char **)args
, environ
);
236 int (*get
)( char ***, int *, int * );
237 int (*set
)( const char *, SdRec
* );
238 void (*commit
)( void );
240 { getNull
, setNull
, 0 },
241 { getGrub
, setGrub
, commitGrub
},
242 { getLilo
, setLilo
, commitLilo
},
246 getBootOptions( char ***opts
, int *def
, int *cur
)
248 return bootOpts
[bootManager
].get( opts
, def
, cur
);
252 setBootOption( const char *opt
, SdRec
*sdr
)
261 if ((ret
= bootOpts
[bootManager
].set( opt
, sdr
)) != BO_OK
)
263 if (!strDup( &sdr
->osname
, opt
))
264 return BO_IO
; /* BO_NOMEM */
270 commitBootOption( void )
273 bootOpts
[bootManager
].commit();
275 free( sdRec.osname );