Bug 36285

Summary: =09Patch (against core dumps) and improvemets for apmd(8)
Product: Base System Reporter: simon <simon>
Component: binAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 4.5-STABLE   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
apmd-patch.tar.gz none

Description simon 2002-03-25 10:20:01 UTC
Following patch fixes several bugs (including core dumps) in apmd(8) and
adds some new features to it.

This is detail description of main changes, number of lines are given
relatively to original source files. Utility nl(1) was used for
enumeration.

--------------------------------------------------------------------------

File /usr/src/sys/i386/include/apm_bios.h

168=09Added new macro APM_NPMEV, which means number of power management
=09codes.

File /usr/src/sys/i386/apm/apm.h
File /usr/src/sys/pc98/apm/apm.h

21=09Removed APM_NPMEV macro, now it is placed in apm_bios.h

File /usr/src/usr.sbin/apmd/apmd.h

36-51=09Theses lines were removed compeletly. This enum {} duplicates
=09PMEV_xxxx macros from the <machine/apm_bios.h>.

95=09Added prototype for the new function Syslog().

File /usr/src/usr.sbin/apmd/apmdparse.y

39=09Removed variable first_time (apmdlex.l was simplified).
=09Added prototypes for yylex() and yyerror().

53=09Fixed incorrect type <str> -> <i>.

56=09Removed toked UNKNOWN (I don't know why it is needed)
=09Added new token ERROR.

67=09lineno is initialized here now.

69-72=09Now config file can be empty, and empty config file is not a config
=09file with incorrect syntax, as it was before.

81=09Don't use abort(), instead use YYABORT to return from yyparse().

109=09Added some cheking for perc > 100, etc. Before it was checked in
=09apmd.c.

110=09Don't use abort(), instead use YYABORT to return from yyparse().

152=09Return value from malloc() was not checked. Fixed.

165=09Return value from malloc() was not checked. Fixed.

175=09Added "| ERROR".

195-198=09Removed completely.

/usr/src/usr.sbin/apmd/apmdlex.l

38=09first_time variable was removed.

40=09Start condition TOP was removed, really it is not needed.

41=09%option nounput was added (try to compile original apmd(8) with
=09option -Wall)

42-48=09Removed completely.

49-91=09All <TOP>s were removed.

85-89=09Incorrect work with the return value from malloc(). Fixed.

92=09Removed completely.
=09Added ".", to catch every unknown character.

94-98=09yyerror() was impruved and fixed: it was able to pass NULL
=09argument to syslog().

/usr/src/usr.sbin/apmd.c

*=09Everything what belong to only this file were marked as static.

*=09Don't use any err/errx/warn/warnx function if we open syslog file.

*=09The -t swicth was added: test config file and output its content.

*=09The -i option was added: number of second between battery state checks
=09(default value were and is now 10 seconds).

*=09All assert() macros were removed.

*=09apmd(8) cought SIGTERM signal, but doesn't terminate itself
=09(proc_signal() and event_loop() functions). Fixed.

60-75=09Complitely rewritten in function init_event_list(). Why? Because PM=
EV_*
=09in <machine/apm_bios.h> are macros and not enum {}.

88=09Return value from malloc() was not checked. Fixed.

130=09Return value from event_cmd_default_clone() was not checked. Fixed.

137=09Don't use err() -> syslog(), return NULL.

155-165=09Why to use out lable? Fixed.

183=09Don't use err() -> syslog(), return NULL.

212-215=09Now these are checked in apmdparse.y, where they should be checke=
d.

220=09Don't use err() -> syslog(), return NULL.

228=09Return value from clone_event_cmd_list() was not checked. Fixed.

249=09Don't use err() -> syslog(), return NULL.

312-321=09Completely was removed. Instead new function turn_events() is
=09introduced.

324-254=09Don't use stderr, use stdout instead.

366-367=09Removed completely. See turn_events() function.

=FA77-381=09Incorrect loop, which cause core dump, when apm_battery {} is u=
sed.
=09Fixed.

387-390=09Rewritten. Now turn_events() function is used and dump_config()
=09function is not called.

398-402=09Rewritten. More checks were added.

407-413=09signal_fd[] and enque_signal() were removed, see below
=09New signal hadlers for SIGCHLD, SIGHUP and SIGTERM (and SIGINT)
=09were added.

421-448=09proc_signal() was simplified. Don't call read(), instead check
=09three volatile sig_atomic_t variables.

449-463=09proc_apmevent() function was improved. More checkes were added

477=09Don't use err().

491=09Don't use err().

515-519=09Improved.

529-533=09Don't use signal_fd[] any more. Simplified.

537=09Why SA_RESTART. Unclear for me, nevertheless I changed this.

545=09Setup SIGINT handler if needed.

554=09Not clear arguments in select() call. Fixed.

563-566=09Rewriten, because signal_fd[] was removed.

576-619=09Added two new switch -t and -i.

=09daemon() function isn't called here, instead new bg_init() function is
=09used: all descriptors are clos()ed, SIGTTOU, SIGTTIN and SIGTSTP are
=09ignored

=09stdin, stdout and sterr -> /dev/null in daemon(0, 1) call

=09fcntl() functions set close-on-exec flags for apmnorm_fd and apmctl_fd

=09And all code here is more clear now.

File /usr/src/usr.sbin/apmd/apmd.8

*=09Some minor fixes (see SYNOPSIS)

*=09Added information about two new switches -t and -i

File /usr/src/usr.sbin/apmd/Makefile

13=09Removed switch -n. apmd(8) knows nothing about it.
=09Fixed name of the configuration file.

--------------------------------------------------------------------------

Results: many bugs were fixed in apmd(8) and two new features
were implemeted.

Unfortunately I don't have any opportunity to check apmd(8) for correct wor=
k
with APM. So, I can't tell anything about this. And please check it with AP=
M.

This patch also fixes problems described in following PRs (all of this
PRs includes correct patches):

bin/30639
bin/30640
i386/32251 (this PR also introduced new feature, which is not a part of
my patch)
i386/35182 (this PR also introduced some signal(SIG_DFL) calls, I'm not sur=
e
that this is needed)

Comments?
Comment 1 gnats freebsd_committer freebsd_triage 2002-05-09 21:12:01 UTC
State Changed
From-To: open->closed

Misfiled PR, resubmitted as bin/36374. 


Comment 2 gnats freebsd_committer freebsd_triage 2002-05-09 21:12:01 UTC
Responsible Changed
From-To: gnats-admin->freebsd-bugs

Misfiled PR.