Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

# Copyright (C) 2011  Internet Systems Consortium, Inc. ("ISC") 

# 

# Permission to use, copy, modify, and distribute this software for any 

# purpose with or without fee is hereby granted, provided that the above 

# copyright notice and this permission notice appear in all copies. 

# 

# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM 

# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL 

# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL 

# INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, 

# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING 

# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 

# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 

# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 

 

from isc.bind10.component import Component, BaseComponent 

import isc.bind10.sockcreator 

from bind10_config import LIBEXECPATH 

import os 

import posix 

import isc.log 

from isc.log_messages.bind10_messages import * 

 

logger = isc.log.Logger("boss") 

 

class SockCreator(BaseComponent): 

    """ 

    The socket creator component. Will start and stop the socket creator 

    accordingly. 

 

    Note: _creator shouldn't be reset explicitly once created.  The 

    underlying Popen object would then wait() the child process internally, 

    which breaks the assumption of the boss, who is expecting to see 

    the process die in waitpid(). 

    """ 

    def __init__(self, process, boss, kind, address=None, params=None): 

        BaseComponent.__init__(self, boss, kind) 

        self.__creator = None 

        self.__uid = boss.uid 

 

    def _start_internal(self): 

        self._boss.curproc = 'b10-sockcreator' 

        self.__creator = isc.bind10.sockcreator.Creator(LIBEXECPATH + ':' + 

                                                        os.environ['PATH']) 

        self._boss.register_process(self.pid(), self) 

        self._boss.set_creator(self.__creator) 

        self._boss.log_started(self.pid()) 

        if self.__uid is not None: 

            logger.info(BIND10_SETUID, self.__uid) 

            posix.setuid(self.__uid) 

 

    def _stop_internal(self): 

        self.__creator.terminate() 

 

    def name(self): 

        return "Socket creator" 

 

    def pid(self): 

        """ 

        Pid of the socket creator. It is provided differently from a usual 

        component. 

        """ 

        return self.__creator.pid() if self.__creator else None 

 

    def kill(self, forceful=False): 

        # We don't really care about forceful here 

exit        if self.__creator: 

            self.__creator.kill() 

 

class Msgq(Component): 

    """ 

    The message queue. Starting is passed to boss, stopping is not supported 

    and we leave the boss kill it by signal. 

    """ 

    def __init__(self, process, boss, kind, address=None, params=None): 

        Component.__init__(self, process, boss, kind, None, None, 

                           boss.start_msgq) 

 

    def _stop_internal(self): 

        """ 

        We can't really stop the message queue, as many processes may need 

        it for their shutdown and it doesn't have a shutdown command anyway. 

        But as it is stateless, it's OK to kill it. 

 

        So we disable this method (as the only time it could be called is 

        during shutdown) and wait for the boss to kill it in the next shutdown 

        step. 

 

        This actually breaks the recommendation at Component we shouldn't 

        override its methods one by one. This is a special case, because 

        we don't provide a different implementation, we completely disable 

        the method by providing an empty one. This can't hurt the internals. 

        """ 

        pass 

 

class CfgMgr(Component): 

    def __init__(self, process, boss, kind, address=None, params=None): 

        Component.__init__(self, process, boss, kind, 'ConfigManager', 

                           None, boss.start_cfgmgr) 

 

class Auth(Component): 

    def __init__(self, process, boss, kind, address=None, params=None): 

        Component.__init__(self, process, boss, kind, 'Auth', None, 

                           boss.start_auth) 

 

class Resolver(Component): 

    def __init__(self, process, boss, kind, address=None, params=None): 

        Component.__init__(self, process, boss, kind, 'Resolver', None, 

                           boss.start_resolver) 

 

class CmdCtl(Component): 

    def __init__(self, process, boss, kind, address=None, params=None): 

        Component.__init__(self, process, boss, kind, 'Cmdctl', None, 

                           boss.start_cmdctl) 

def get_specials(): 

    """ 

    List of specially started components. Each one should be the class than can 

    be created for that component. 

    """ 

    return { 

        'sockcreator': SockCreator, 

        'msgq': Msgq, 

        'cfgmgr': CfgMgr, 

        # TODO: Should these be replaced by configuration in config manager only? 

        # They should not have any parameters anyway 

        'auth': Auth, 

        'resolver': Resolver, 

        'cmdctl': CmdCtl 

    }