Skip to content

Commit

Permalink
shm is recreated with SIGALRM (in active term) after an external shm_…
Browse files Browse the repository at this point in the history
…unlink
  • Loading branch information
Goheeca committed May 19, 2019
1 parent 02d1d12 commit d0f824f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/fbterm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ void FbTerm::processSignal(u32 signo)

case SIGALRM:
FbShellManager::instance()->drawCursor();
Screen::instance()->checkBackgroundPath();
break;

case SIGUSR1:
Expand Down
1 change: 1 addition & 0 deletions src/screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public :
virtual void switchVc(bool enter);

void redrawBg();
void checkBackgroundPath();

protected:
u32 mWidth, mHeight;
Expand Down
29 changes: 21 additions & 8 deletions src/screen_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,8 @@ void Screen::initFillDraw()
bgimage_mem = new u8[mSize];
if (!backgroundPath) {
memcpy(bgimage_mem, mVMemBase, mSize);
} else if ((mBackgroundFd = shm_open(backgroundPath, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR)) != -1) {
ftruncate(mBackgroundFd, mSize);
int falloc = 0;
if (falloc = fallocate(mBackgroundFd, FALLOC_FL_ZERO_RANGE, 0, mSize)) {
mBackgroundData = mmap(NULL, mSize, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE, mBackgroundFd, 0);
mempcpy(bgimage_mem, mBackgroundData, mSize);
snprintf((char *)mBackgroundData, mSize, "%u", getpid());
}
} else {
checkBackgroundPath();
}
}

Expand Down Expand Up @@ -141,6 +135,25 @@ void Screen::redrawBg()
}
}

void Screen::checkBackgroundPath() {
int oldFd = mBackgroundFd;
if ((mBackgroundFd = shm_open(backgroundPath, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR)) != -1) {
if (oldFd != -1) {
if (mBackgroundData != MAP_FAILED) {
munmap(mBackgroundData, mSize);
}
close(oldFd);
}
ftruncate(mBackgroundFd, mSize);
int falloc = 0;
if (falloc = fallocate(mBackgroundFd, FALLOC_FL_ZERO_RANGE, 0, mSize)) {
mBackgroundData = mmap(NULL, mSize, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE, mBackgroundFd, 0);
mempcpy(bgimage_mem, mBackgroundData, mSize);
snprintf((char *)mBackgroundData, mSize, "%u", getpid());
}
}
}

void Screen::fillX(u32 x, u32 y, u32 w, u8 color)
{
u32 c = fillColors[color];
Expand Down

0 comments on commit d0f824f

Please sign in to comment.