1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/misc/CheckAccessDeleted.h
12 #ifndef ZYPP_MISC_CHECKACCESSDELETED_H
13 #define ZYPP_MISC_CHECKACCESSDELETED_H
19 ///////////////////////////////////////////////////////////////////
21 { /////////////////////////////////////////////////////////////////
24 * Check for running processes which access deleted executables or libraries.
26 * Executed after commit, this gives a hint which processes/services
27 * need to be restarted.
29 * Per default upon construction or explicit call to \ref check,
30 * information about running processes which access deleted files
31 * or libraries is collected and provided as a \ref ProcInfo
34 class CheckAccessDeleted
39 * Data about one running process accessing deleted files.
43 std::string pid; //!< process ID
44 std::string ppid; //!< parent process ID
45 std::string puid; //!< process user ID
46 std::string login; //!< process login name
47 std::string command; //!< process command name
48 std::vector<std::string> files; //!< list of deleted executables or libraries accessed
50 /** Guess if command was started by a systemd service script.
51 * The service name might be used to restart the service.
52 * \warning This is just a guess.
54 std::string service() const;
57 typedef size_t size_type;
58 typedef ProcInfo value_type;
59 typedef std::vector<ProcInfo>::const_iterator const_iterator;
62 /** Default ctor performs check immediately.
63 * Pass \c false and the initial check is omitted.
64 * \throws Exception if \ref check throws.
67 CheckAccessDeleted( bool doCheck_r = true )
68 { if ( doCheck_r ) check(); }
71 /** Check for running processes which access deleted executables or libraries.
73 * Per default \ref check will try guess and collect executables and
74 * libraries only by looking at the files path and name. (e.g named
75 * \c lib* or located in \c *bin/).
77 * A verbose check will omit this test and collect all processes using
80 * \return the number of processes found.
81 * \throws Exception On error collecting the data (e.g. no lsof installed)
83 size_type check( bool verbose_r = false );
85 bool empty() const { return _data.empty(); }
86 size_type size() const { return _data.size(); }
87 const_iterator begin() const { return _data.begin(); }
88 const_iterator end() const { return _data.end(); }
91 /** Guess if pid was started by a systemd service script.
92 * The service name might be used to restart the service.
93 * \warning This is just a guess.
95 static std::string findService( pid_t pid_r );
98 std::vector<ProcInfo> _data;
100 ///////////////////////////////////////////////////////////////////
102 /** \relates CheckAccessDeleted Stream output */
103 std::ostream & operator<<( std::ostream & str, const CheckAccessDeleted & obj );
105 /** \relates CheckAccessDeleted::ProcInfo Stream output */
106 std::ostream & operator<<( std::ostream & str, const CheckAccessDeleted::ProcInfo & obj );
108 /////////////////////////////////////////////////////////////////
110 ///////////////////////////////////////////////////////////////////
111 #endif // ZYPP_MISC_CHECKACCESSDELETED_H