Switch to unified view

a/src/sysvshm.cpp b/src/sysvshm.cpp
...
...
54
    size_t  bytes{0};
54
    size_t  bytes{0};
55
    // Delete seg or leave it behind. 
55
    // Delete seg or leave it behind. 
56
    bool removeondelete{true};
56
    bool removeondelete{true};
57
    bool ok{false};
57
    bool ok{false};
58
    bool mycreation{false};
58
    bool mycreation{false};
59
    int lasterrno;
59
};
60
};
60
61
61
void ShmSeg::setremove(bool onoff)
62
void ShmSeg::setremove(bool onoff)
62
{
63
{
63
    m->removeondelete = onoff;
64
    m->removeondelete = onoff;
...
...
74
}
75
}
75
76
76
bool ShmSeg::ok()
77
bool ShmSeg::ok()
77
{
78
{
78
    return m->ok;
79
    return m->ok;
80
}
81
int ShmSeg::geterrno()
82
{
83
    return m->lasterrno;
79
}
84
}
80
85
81
ShmSeg::ShmSeg(key_t ky, size_t size, bool create, int perms)
86
ShmSeg::ShmSeg(key_t ky, size_t size, bool create, int perms)
82
    : m(new Internal)
87
    : m(new Internal)
83
{
88
{
...
...
94
    if (create) {
99
    if (create) {
95
        flags = IPC_CREAT|IPC_EXCL;
100
        flags = IPC_CREAT|IPC_EXCL;
96
    } else {
101
    } else {
97
        perms = 0;
102
        perms = 0;
98
    }
103
    }
104
    m->lasterrno = 0;
99
    if ((m->shmid = shmget(m->key, size, flags|perms)) >= 0) {
105
    if ((m->shmid = shmget(m->key, size, flags|perms)) >= 0) {
100
        if (create) {
106
        if (create) {
101
            m->mycreation = true;
107
            m->mycreation = true;
102
        }
108
        }
103
    } else {
109
    } else {
110
        m->lasterrno = errno;
104
        if (errno != EEXIST) {
111
        if (errno != EEXIST) {
112
            // Don't log a possibly trivial error, let the caller do it if
113
            // needed.
114
            // LOGSYSERR("ShmSeg::ShmSeg", "shmget", size);
115
            return;
116
        }
117
        // If the segment already existed, let's attach it
118
        m->lasterrno = 0;
119
        if ((m->shmid = shmget(m->key, size, 0)) < 0) {
120
            m->lasterrno = errno;
105
            LOGSYSERR("ShmSeg::ShmSeg", "shmget", size);
121
            LOGSYSERR("ShmSeg::ShmSeg", "shmget", size);
106
            return;
122
            return;
107
        }
123
        }
108
        if ((m->shmid = shmget(m->key, size, 0)) < 0) {
109
            LOGSYSERR("ShmSeg::ShmSeg", "shmget", size);
110
            return;
111
        }
112
    }
124
    }
113
    m->bytes = size;
125
    m->bytes = size;
114
    // Attach it
126
    // Attach it
127
    m->lasterrno = 0;
115
    if ((m->seg = shmat(m->shmid, 0, 0)) == (void *)-1) {
128
    if ((m->seg = shmat(m->shmid, 0, 0)) == (void *)-1) {
129
        m->lasterrno = errno;
116
        LOGSYSERR("ShmSeg::ShmSeg", "shmat", m->shmid);
130
        LOGSYSERR("ShmSeg::ShmSeg", "shmat", m->shmid);
117
        shmctl(m->shmid, IPC_RMID, 0);
131
        shmctl(m->shmid, IPC_RMID, 0);
118
        return;
132
        return;
119
    }
133
    }
120
    m->ok = true;
134
    m->ok = true;
121
}
135
}
122
136
123
ShmSeg::ShmSeg(const char*pathname, int proj_id, size_t size, bool create, int perms)
137
ShmSeg::ShmSeg(const char*pathname, int proj_id, size_t size, bool create,
138
               int perms)
124
    : ShmSeg(ftok(pathname, proj_id), size, create, perms)
139
    : ShmSeg(ftok(pathname, proj_id), size, create, perms)
125
{
140
{
126
}
141
}
127
142
128
ShmSeg::~ShmSeg()
143
ShmSeg::~ShmSeg()